diff --git a/package.json b/package.json index b83972140..a0ce641c3 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } } diff --git a/src/bucket.ts b/src/bucket.ts index e3a660f88..3c5d1b8b9 100644 --- a/src/bucket.ts +++ b/src/bucket.ts @@ -2187,7 +2187,7 @@ class Bucket extends ServiceObject { }, }); } catch (e) { - callback!(e); + callback!(e as Error); return; } finally { this.storage.retryOptions.autoRetry = this.instanceRetryValue; @@ -4091,7 +4091,7 @@ class Bucket extends ServiceObject { if (!options.force) { throw e; } - errors.push(e); + errors.push(e as Error); } }; diff --git a/src/file.ts b/src/file.ts index 8c3da1143..aa1e1bc8a 100644 --- a/src/file.ts +++ b/src/file.ts @@ -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'; @@ -1461,7 +1460,7 @@ class File extends ServiceObject { try { await this.getMetadata({userProject: options.userProject}); } catch (e) { - throughStream.destroy(e); + throughStream.destroy(e as Error); return; } if (this.metadata.contentEncoding === 'gzip') { @@ -2565,7 +2564,7 @@ class File extends ServiceObject { fields, }; } catch (err) { - throw new SigningError(err.message); + throw new SigningError((err as Error).message); } }; diff --git a/src/gcs-resumable-upload.ts b/src/gcs-resumable-upload.ts index 6dff3d704..5a28f7419 100644 --- a/src/gcs-resumable-upload.ts +++ b/src/gcs-resumable-upload.ts @@ -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'); diff --git a/src/signer.ts b/src/signer.ts index 8af898730..416970a20 100644 --- a/src/signer.ts +++ b/src/signer.ts @@ -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; } }; @@ -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; } }; diff --git a/system-test/storage.ts b/system-test/storage.ts index 4ce25bce2..df19fa184 100644 --- a/system-test/storage.ts +++ b/system-test/storage.ts @@ -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']; @@ -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)) + ); } }); }); @@ -2217,7 +2227,7 @@ describe('storage', () => { const file = FILES[filesKey]; const hash = crypto.createHash('md5'); - return new Promise(resolve => + return new Promise(resolve => fs .createReadStream(file.path) .on('data', hash.update.bind(hash)) @@ -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; diff --git a/test/bucket.ts b/test/bucket.ts index 8e7b25fdf..29e28b51f 100644 --- a/test/bucket.ts +++ b/test/bucket.ts @@ -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; + delete urlConfig.action; assert.throws(() => { - bucket.getSignedUrl(SIGNED_URL_CONFIG, () => {}), + bucket.getSignedUrl(urlConfig, () => {}), ExceptionMessages.INVALID_ACTION; }); }); diff --git a/test/file.ts b/test/file.ts index e797bf68f..16c6466fe 100644 --- a/test/file.ts +++ b/test/file.ts @@ -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; + delete urlConfig.action; assert.throws(() => { - file.getSignedUrl(SIGNED_URL_CONFIG, () => {}), + file.getSignedUrl(urlConfig, () => {}), ExceptionMessages.INVALID_ACTION; }); }); @@ -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'); } });