Skip to content
This repository was archived by the owner on Feb 20, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
055eeef
Add error sample
vishald123 Jul 30, 2019
0621d0b
test sample
vishald123 Jul 30, 2019
baddb0c
Merge pull request #2 from vishald123/add-error-file
vishald123 Jul 30, 2019
b61b9ea
Merge branch 'master' into master
vishald123 Jul 31, 2019
98b2702
Merge branch 'master' into master
vishald123 Jul 31, 2019
87d30a5
lint_fix
vishald123 Jul 31, 2019
2d9e89a
Merge branch 'master' into master
vishald123 Aug 1, 2019
c75e083
lint
AVaksman Aug 2, 2019
0a87d4f
Merge branch 'master' into master
AVaksman Aug 5, 2019
bd28f35
Merge branch 'master' into master
AVaksman Aug 13, 2019
93a0776
Suggested changes
vishald123 Aug 20, 2019
cadcab4
Suggested changes
vishald123 Aug 20, 2019
54359b5
Suggested changes
vishald123 Aug 20, 2019
89c9159
Copyright changes
vishald123 Aug 20, 2019
6ea8cd0
Copyright changes
vishald123 Aug 20, 2019
4d84dde
Copyright changes
vishald123 Aug 20, 2019
8148a1b
test
vishald123 Aug 20, 2019
a0adc19
test
vishald123 Aug 20, 2019
fd586b6
test
vishald123 Aug 20, 2019
76e5f32
test
vishald123 Aug 20, 2019
5dd8d0d
refactor: header
AVaksman Aug 20, 2019
e141a7b
refactor: header2
AVaksman Aug 20, 2019
90e6458
fix: headers should pass now
AVaksman Aug 22, 2019
7737bfb
Merge branch 'master' into master
AVaksman Aug 22, 2019
d0cad63
refactor: simplify the example
AVaksman Aug 22, 2019
c12938c
Merge branch 'master' into master
AVaksman Aug 25, 2019
924246b
Merge branch 'master' into master
vishald123 Aug 26, 2019
b37fd46
Merge branch 'master' into master
AVaksman Aug 29, 2019
9d5f2b9
Merge branch 'master' into master
AVaksman Sep 3, 2019
19bb7bb
Merge branch 'master' into master
AVaksman Sep 5, 2019
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
52 changes: 52 additions & 0 deletions samples/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright 2019 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// sample-metadata
// title: error sample
// description: sample show how to handle and process error
// usage: node error.js

const {Datastore} = require('@google-cloud/datastore');

// [START error]
function main() {
// Creates a client
const datastore = new Datastore();

const query = datastore.createQuery(['Company']).start('badrequest');

async function runQuery() {
try {
const [result] = await datastore.runQuery(query);
// etc., etc.
return result;
} catch (error) {
// do something with error.
console.log(error.code); // 3
//Forward the error to caller
throw error;
}
}

runQuery().catch(err => {
console.log(err.message); // "Error parsing protocol message"
});
// [END error]
}

main(...process.argv.slice(2));
33 changes: 33 additions & 0 deletions samples/test/error.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright 2019 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

const assert = require('assert');
const {execSync} = require('child_process');
const exec = cmd =>
execSync(cmd, {
encoding: 'utf8',
});

describe('error', () => {
it('should have an error', done => {
const errorCode = 3;
const output = exec(`node error.js`);
assert.strictEqual(parseInt(output[0]), errorCode);
done();
});
});