Exception not thrown on syntax error
See original GitHub issueEnvironment details
- OS: MacOS
- Node.js version: 12.18
- npm version: 6.14.4
@google-cloud/bigquery
version: 5.3.0
Steps to reproduce
it("throws on bigquery syntax error", async () => {
const bq = new BigQuery({ projectId: "REDACTED" })
const [job] = await bq.createQueryJob({
query: `DECLARE foo DEFAULT ( SELECT 1 );
SELECT 1 FROM XYZ`,
timeoutMs: 5000,
location: "US"
})
const [rows] = await job.getQueryResults()
assert.strictEqual(rows.length, 0)
})
Expected result:
Invalid value: Table name “XYZ” missing dataset while no default dataset is set in the request. at [2:1]
Actual result No exception is thrown, rows.length = 0
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Why browser is not throwing exception for syntax error?
I accidentally wrote a wrong JavaScript syntax (I think so). code is var temp = {}; temp.a = 34; height:34, //should fail here....
Read more >How to Throw Exceptions in Python - Rollbar
The syntax error exception occurs when the code does not conform to Python keywords, naming style, or programming structure.
Read more >throw - JavaScript - MDN Web Docs - Mozilla
The throw statement throws a user-defined exception. Execution of the current function will stop (the statements after throw won't be ...
Read more >Exceptions in Java
A program containing one or more syntax errors is ill-formed. ... execution could result in a checked exception being thrown (but not caught)...
Read more >Exceptions - Manual - PHP
The thrown object must be an instanceof Throwable. Trying to throw an object that is not will result in a PHP Fatal Error....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The issue here is that scripting statements like this generate child jobs for each statement. When you call
job.getQueryResults
using the original parent job, what’s returned is the result of the last statement that executed. So, in the case of your example, it returns the empty results from theDECLARE
statement’s execution.To obtain the results of all statements in the script, you must enumerate the child jobs and call
jobs.getQueryResults
on each of them. You can access the list of child jobs by setting theparentJobId
option in abigquery.getJobs
call.Here is how you would access the error from your example:
Documentation for this concept is here.
I actually have a similar problem but not with table name but with an incorrect field name. There’s no error thrown, just an empty result. In the Google Console the job did error.