Skip to content

Commit c20a087

Browse files
callmehiphopJustinBeckwith
authored andcommitted
feat: throw errors for missing resource ids (#342)
1 parent b3ca0c8 commit c20a087

4 files changed

Lines changed: 20 additions & 0 deletions

File tree

handwritten/bigquery/src/dataset.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,8 @@ class Dataset extends ServiceObject {
621621
/**
622622
* Create a Table object.
623623
*
624+
* @throws {TypeError} if table ID is missing.
625+
*
624626
* @param {string} id The ID of the table.
625627
* @param {object} [options] Table options.
626628
* @param {string} [options.location] The geographic location of the table, by
@@ -639,6 +641,10 @@ class Dataset extends ServiceObject {
639641
* const institutions = dataset.table('institution_data');
640642
*/
641643
table(id: string, options?: TableOptions) {
644+
if (typeof id !== 'string') {
645+
throw new TypeError('A table ID is required.');
646+
}
647+
642648
options = extend(
643649
{
644650
location: this.location,

handwritten/bigquery/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,10 @@ export class BigQuery extends common.Service {
11631163
* const dataset = bigquery.dataset('higher_education');
11641164
*/
11651165
dataset(id: string, options?: DataSetOptions) {
1166+
if (typeof id !== 'string') {
1167+
throw new TypeError('A dataset ID is required.');
1168+
}
1169+
11661170
if (this.location) {
11671171
options = extend({location: this.location}, options);
11681172
}

handwritten/bigquery/test/dataset.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,11 @@ describe('BigQuery/Dataset', () => {
785785
});
786786

787787
describe('table', () => {
788+
it('should throw an error if the id is missing', () => {
789+
const expectedErr = /A table ID is required\./;
790+
assert.throws(() => ds.table(), expectedErr);
791+
});
792+
788793
it('should return a Table object', () => {
789794
const tableId = 'tableId';
790795
const table = ds.table(tableId);

handwritten/bigquery/test/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,11 @@ describe('BigQuery', () => {
12481248
describe('dataset', () => {
12491249
const DATASET_ID = 'dataset-id';
12501250

1251+
it('should throw an error if the id is missing', () => {
1252+
const expectedErr = /A dataset ID is required\./;
1253+
assert.throws(() => bq.dataset(), expectedErr);
1254+
});
1255+
12511256
it('returns a Dataset instance', () => {
12521257
const ds = bq.dataset(DATASET_ID);
12531258
assert(ds instanceof FakeDataset);

0 commit comments

Comments
 (0)