Why am I getting a runtime error "Object expected" in - If (fs.FileExists(filename)) ?
var filename = "d:\\list.txt";
fs = new ActiveXObject("Scripting.FileSystemObject");
If (fs.FileExists(filename)) //i 'm getting a runtime error "Object expected" here
{
// Open the file
}
Change If to if. JScript is a case-sensitive language.
Related
I had a stored procedure to insert the data from a stage which is called by task. if the load fails(due to on_error= skip_file option) it throws an error which is handled. but the status of the task shows as success. what to do to make the task fail when there is error in stored procedure.
here is the sample code
create or replace procedure sample_procedure()
returns varchar not null
language javascript
execute as caller
as
$$
try
{
try
{
var ct_table_cmd = `create or replace table sample_table_temp like sample_table`;
var ct_table_stmt = snowflake.createStatement({sqlText: ct_table_cmd});
var result_set= ct_table_stmt.execute();
result_set.next();
}
catch(err)
{
var queryId = ct_table_stmt.getQueryId();
var queryText = ct_table_stmt.getSqlText();
var log_insert_into=snowflake.createStatement({sqlText:`insert into error_table
(code, message, queryid, querytext) VALUES (?,?,?,?);`
,binds : [err.code, err.message,queryId,queryText]
});
log_insert_into.execute();
var ct_task_ret_value = snowflake.createStatement({sqlText: `call system$set_return_value('{err.message'});`}).execute();
return err.message;
}
var copy_cmd = `copy into smaple_table_temp from #mystage
file_format=(format_name= 'sample_csv_format')
files=('/file_name')
on_error=skip_file;`;
var copy_cmd_stmt = snowflake.createStatement({sqlText:copy_cmd});
var result_set =copy_cmd_stmt.execute();
result_set.next();
if(result_set.getColumnValue(2)=='LOADED')
{
var swap_cmd = `alter table sample_table_temp swap with sample_table;`;
var swap_stmt = snowflake.createStatement({sqlText: swap_cmd});
swap_stmt.execute();
}
else if (result_set.getColumnValue(2)== 'LOAD_FAILED')
{
var err_message= result_set.getColumnValue(7);
var queryId = copy_cmd_stmt.getQueryId();
var queryText = copy_cmd_stmt.getSqlText();
var log_insert_into=snowflake.createStatement({sqlText:`insert into error_table
(code, message, queryid, querytext) VALUES (?,?,?,?);`
,binds : [err.code, err.message,queryId,queryText]
});
var task_ret_value = snowflake.createStatement({sqlText: `call system$set_return_value('{err_message'});`}).execute();
log_insert_into.execute();
return err_message
}
}
$$
;
The error log table and task to call the procedure is :
create or replace table error_table (ts timestamp_ntz, src varchar(50),code varhcar(100) ,
message varchar, queryid varchar, querytext varhcar);
create or replace task sample task
warehouse = 'my_warehouse'
schedule= '10 minute'
as
call sample_procedure();
when the task call the procedure with no data in the location it throws an error in the task history as "execution error in stored procedure sample procedure:
SQL compilation error:
Syntax error line at position 47 unexpected 'remote'. at statement.execute, line 172 position 111". but the actual error is "remote file is not existed at. there are several potential causes. The file might not exist. The required credentials may be missing or invalid."
and when the table is not existed, the error shown is different in task_history of information schema. It is not showing the error which is shown when the procedure is called independently (i.e call sample_procdure()).
Any suggestions are helpful.
You're setting the return value for the task here:
var ct_task_ret_value = snowflake.createStatement({sqlText: `call system$set_return_value('{err.message'});`}).execute();
You're setting the return for the stored procedure here:
return err.message;
The problem is err.message is a string containing the text of an error message, which is not an error indication. You've caught the error, so as far as Snowflake's concerned it's been handled.
To indicate an error on SP execution, you can either 1) not catch the error or 2) catch the error, handle it, and throw an error.
Option 2 seems to be what you're looking to do. Catch the error as you're already doing, but instead of returning err.message, do this:
//return err.message;
throw err.message;
Snowflake will wrap the error message with its own error text. There is currently no way to avoid that, so you may want to do something in the text to call out attention to your error text like *wrapping in stars* or something like that. Snowflake Stored Procedure Exception & Failure
What is the meaning of the following error message:
I am attempting to convert the dogfood.nt to its rdf/xml representation form, what does the StackOverflow message indicate ?
<j.12:Person rdf:about="http://data.semanticweb.org/person/rich-keller">
<j.12:name>Rich Keller</j.12:name>
<rdfs:label>Rich Keller</rdfs:label>
<j.3:affiliation rdf:resource="http://data.semanticweb.org/organization/nasa-ames-research-center"/>
<j.4:holdsRole rdf:resource="http://data.semanticweb.org/conference/iswc/2005/pc-member-at-iswc2005-research-track"/>
</j.12:PersException in thread "main" java.lang.StackOverflowError
at java.util.regex.Pattern$BranchConn.match(Pattern.java:4568)
at java.util.regex.Pattern$GroupTail.match(Pattern.java:4717)
at java.util.regex.Pattern$BranchConn.match(Pattern.java:4568)
at java.util.regex.Pattern$GroupTail.match(Pattern.java:4717)
at java.util.regex.Pattern$Curly.match0(Pattern.java:4272)
at java.util.regex.Pattern$Curly.match(Pattern.java:4234)
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4658)
at java.util.regex.Pattern$Branch.match(Pattern.java:4604)
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4658)
at java.util.regex.Pattern$Branch.match(Pattern.java:4604)
at java.util.regex.Pattern$Branch.match(Pattern.java:4602)
Following is the code snippet used:
Model model11 = ModelFactory.createDefaultModel();
InputStream is1 = FileManager.get().open("dogfood4.nt");
if (is1 != null) {
model11.read(is1, null, "N-TRIPLE");
model11.write(os1, "RDF/XML");
} else {
System.err.println("cannot read file ");;
}
I am using the semantic dogfood n-triples.
I am trying the following code:
if (sem_post(sem) == -1)
{
printf("syncr_release error %d\n", errno);
perror("Error:");
return ERROR;
}
and it's giving the following output:
syncr_release error 9
Error:: Bad file descriptor
I cannot find anything about that error code in the documentation about sem_post(). How can I solve this?
I configured the highchart export server for Java from the current master in GitHub. When I tried to export an image using the demo page a corrupted file was returned. I have debugged to code and found out the following message is returned as the result in validate method in ServerObjectFactory.java
String result = server.request("{\"status\":\"isok\"}");
The value of the result String is "Failed rendering:SyntaxError: Unable to parse JSON string"
What can be the cause for this issue.
Thank You
That's very strange. The syntax of the JSON string is syntactically correct. I can point out where from the error is generated.
In the highcharts-convert.js file in highcharts-ecport-convert/src/main/resources/phantomjs the incoming request is expected to be a JSON string and is parsed, see Line 469
function (request, response) {
var jsonStr = request.post,
params,
msg;
try {
params = JSON.parse(jsonStr); // L469
if (params.status) {
// for server health validation
response.statusCode = 200;
response.write('OK');
response.close();
} else {
....
Set in a console.log(jsonStr) before JSON.parse(jsonStr) . I hope this give you a clue of why it's throwing a error.
This script is getting Microsoft JScript runtime error: Object expected on If (out_params.bGranted) line. It seems like this is related to a syntax error, but I can't find it. This code, in its current form, was basically copied from Invoking functions with `out` arguments, passing arguments by reference in JScript.
function main()
{
var provider_name = "StdRegProv";
var func_name = "CheckAccess";
var services = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\default"); // connect to WMI
var registry = services.Get(provider_name); // get provider
var in_params = registry.Methods_(func_name).InParameters.SpawnInstance_();
in_params.hDefKey = 0x80000001;
in_params.sSubKeyName = "Software\\Microsoft\\Shared Tools\\Proofing Tools\\1.0\\Override";
in_params.uRequired = 65536;
var out_params = services.ExecMethod(provider_name, func_name, in_params);
If (out_params.bGranted)
{
WScript.Echo("Has DELETE Access Rights on HKCU " + strKeyPath);
registry.DeleteKey (HKCU, strKeyPath);
}
Else
{
WScript.Echo("No DELETE Access Rights on HKCU " + strKeyPath);
}
}
main();
In JScript, keywords (and identifiers) are case-sensitive, so you cannot use If instead of if, Elseinstead of else, and so on.
In your example the script engine interprets If (out_params.bGranted) as a function call, which results in a runtime error since you obviously did not defined an If function.