Skip to content

Commit

Permalink
fix: update typescript to 4.6.3 and fix resulting errors (googleapis#…
Browse files Browse the repository at this point in the history
…1878)

* fix: update typescript to 4.6.3 and fix resulting errors

* remove unused variables

* use http error instead of any
  • Loading branch information
ddelgrosso1 committed May 23, 2022
1 parent 270076f commit 0c9485d
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"@types/mime-types": "^2.1.0",
"@types/mocha": "^8.0.0",
"@types/mockery": "^1.4.29",
"@types/node": "^16.0.0",
"@types/node": "^17.0.25",
"@types/node-fetch": "^2.1.3",
"@types/proxyquire": "^1.3.28",
"@types/pumpify": "^1.4.1",
Expand All @@ -109,7 +109,7 @@
"proxyquire": "^2.1.3",
"sinon": "^14.0.0",
"tmp": "^0.2.0",
"typescript": "~3.9.10",
"typescript": "^4.6.4",
"yargs": "^16.0.0"
}
}
4 changes: 2 additions & 2 deletions src/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2187,7 +2187,7 @@ class Bucket extends ServiceObject {
},
});
} catch (e) {
callback!(e);
callback!(e as Error);
return;
} finally {
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
Expand Down Expand Up @@ -4091,7 +4091,7 @@ class Bucket extends ServiceObject {
if (!options.force) {
throw e;
}
errors.push(e);
errors.push(e as Error);
}
};

Expand Down
5 changes: 2 additions & 3 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import * as fs from 'fs';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const hashStreamValidation = require('hash-stream-validation');
import * as mime from 'mime';
import * as os from 'os';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pumpify = require('pumpify');
import * as resumableUpload from './gcs-resumable-upload';
Expand Down Expand Up @@ -1461,7 +1460,7 @@ class File extends ServiceObject<File> {
try {
await this.getMetadata({userProject: options.userProject});
} catch (e) {
throughStream.destroy(e);
throughStream.destroy(e as Error);
return;
}
if (this.metadata.contentEncoding === 'gzip') {
Expand Down Expand Up @@ -2565,7 +2564,7 @@ class File extends ServiceObject<File> {
fields,
};
} catch (err) {
throw new SigningError(err.message);
throw new SigningError((err as Error).message);
}
};

Expand Down
1 change: 0 additions & 1 deletion src/gcs-resumable-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {RetryOptions, PreconditionOptions} from './storage';
import * as uuid from 'uuid';

const NOT_FOUND_STATUS_CODE = 404;
const TERMINATED_UPLOAD_STATUS_CODE = 410;
const RESUMABLE_INCOMPLETE_STATUS_CODE = 308;
const DEFAULT_API_ENDPOINT_REGEX = /.*\.googleapis\.com/;
const packageJson = require('../../package.json');
Expand Down
10 changes: 6 additions & 4 deletions src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ export class URLSigner {
Signature: signature,
} as V2SignedUrlQuery;
} catch (err) {
const signingErr = new SigningError(err.message);
signingErr.stack = err.stack;
const error = err as Error;
const signingErr = new SigningError(error.message);
signingErr.stack = error.stack;
throw signingErr;
}
};
Expand Down Expand Up @@ -318,8 +319,9 @@ export class URLSigner {
});
return signedQuery;
} catch (err) {
const signingErr = new SigningError(err.message);
signingErr.stack = err.stack;
const error = err as Error;
const signingErr = new SigningError(error.message);
signingErr.stack = error.stack;
throw signingErr;
}
};
Expand Down
17 changes: 14 additions & 3 deletions system-test/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ import {PubSub} from '@google-cloud/pubsub';
import {LifecycleRule} from '../src/bucket';
import {IdempotencyStrategy} from '../src/storage';

class HTTPError extends Error {
code: number;
constructor(message: string, code: number) {
super(message);
this.code = code;
}
}

// When set to true, skips all tests that is not compatible for
// running inside VPCSC.
const RUNNING_IN_VPCSC = !!process.env['GOOGLE_CLOUD_TESTS_IN_VPCSC'];
Expand Down Expand Up @@ -198,7 +206,9 @@ describe('storage', () => {
/Could not load the default credentials/,
/does not have storage\.objects\.create access/,
];
assert(allowedErrorMessages.some(msg => msg.test(e.message)));
assert(
allowedErrorMessages.some(msg => msg.test((e as Error).message))
);
}
});
});
Expand Down Expand Up @@ -2217,7 +2227,7 @@ describe('storage', () => {
const file = FILES[filesKey];
const hash = crypto.createHash('md5');

return new Promise(resolve =>
return new Promise<void>(resolve =>
fs
.createReadStream(file.path)
.on('data', hash.update.bind(hash))
Expand Down Expand Up @@ -3943,7 +3953,8 @@ describe('storage', () => {
return false;
}
} catch (error) {
if (error.code === 404) {
const err = error as HTTPError;
if (err.code === 404) {
return false;
} else {
throw error;
Expand Down
7 changes: 5 additions & 2 deletions test/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2079,9 +2079,12 @@ describe('Bucket', () => {
});

it('should error if action is undefined', () => {
delete SIGNED_URL_CONFIG.action;
const urlConfig = {
...SIGNED_URL_CONFIG,
} as Partial<GetBucketSignedUrlConfig>;
delete urlConfig.action;
assert.throws(() => {
bucket.getSignedUrl(SIGNED_URL_CONFIG, () => {}),
bucket.getSignedUrl(urlConfig, () => {}),
ExceptionMessages.INVALID_ACTION;
});
});
Expand Down
7 changes: 4 additions & 3 deletions test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3519,9 +3519,10 @@ describe('File', () => {
});

it('should error if action is undefined', () => {
delete SIGNED_URL_CONFIG.action;
const urlConfig = {...SIGNED_URL_CONFIG} as Partial<GetSignedUrlConfig>;
delete urlConfig.action;
assert.throws(() => {
file.getSignedUrl(SIGNED_URL_CONFIG, () => {}),
file.getSignedUrl(urlConfig, () => {}),
ExceptionMessages.INVALID_ACTION;
});
});
Expand Down Expand Up @@ -4264,7 +4265,7 @@ describe('File', () => {
await file.save(DATA, options);
throw Error('unreachable');
} catch (e) {
assert.strictEqual(e.message, 'first error');
assert.strictEqual((e as Error).message, 'first error');
}
});

Expand Down

0 comments on commit 0c9485d

Please sign in to comment.