Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(job): check for errorResult when polling jobs #387

Merged
merged 3 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions src/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,28 +454,23 @@ class Job extends Operation {
* @param {function} callback
*/
poll_(callback: MetadataCallback): void {
this.getMetadata(
(err: Error, metadata: Metadata, apiResponse: r.Response) => {
// tslint:disable-next-line no-any
if (!err && (apiResponse as any).status &&
// tslint:disable-next-line no-any
(apiResponse as any).status.errors) {
// tslint:disable-next-line no-any
err = new util.ApiError((apiResponse as any).status);
}

if (err) {
callback(err);
return;
}

if (metadata.status.state !== 'DONE') {
callback(null);
return;
}

callback(null, metadata);
});
this.getMetadata((err: Error, metadata: Metadata) => {
if (!err && metadata.status && metadata.status.errorResult) {
err = new util.ApiError(metadata.status);
}

if (err) {
callback(err);
return;
}

if (metadata.status.state !== 'DONE') {
callback(null);
return;
}

callback(null, metadata);
});
}
}

Expand Down
5 changes: 3 additions & 2 deletions test/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,16 @@ describe('BigQuery/Job', () => {
const error = new Error('Error.');
const apiResponse = {
status: {
errors: error,
errorResult: error,
errors: [error],
},
};

const sandbox = sinon.createSandbox();

beforeEach(() => {
job.getMetadata = (callback: Function) => {
callback(null, apiResponse, apiResponse);
callback(null, apiResponse);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it would be cool if we could get a test case around this change in behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually thought this was a behavior change that wasn't pulled over to BigQuery correctly, but now that you said this I think we might have stumbled on to a bug in nodejs-common

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nevermind, my initial guess was right. There was a breaking change in common 0.28.0 and the fix apparently never found its way here.

};
});

Expand Down