1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- import * as common from '@google-cloud/common' ;
1615import { promisifyAll } from '@google-cloud/promisify' ;
1716import arrify = require( 'arrify' ) ;
1817import { ServiceError } from 'google-gax' ;
@@ -38,7 +37,7 @@ import {Mutation} from './mutation';
3837import { Row } from './row' ;
3938import { ChunkTransformer } from './chunktransformer' ;
4039import { CallOptions } from 'google-gax' ;
41- import { Bigtable } from '.' ;
40+ import { Bigtable , AbortableDuplex } from '.' ;
4241import { Instance } from './instance' ;
4342import { google } from '../protos/protos' ;
4443import { Duplex } from 'stream' ;
@@ -353,12 +352,12 @@ export type GetRowsCallback = (
353352) => void ;
354353export type GetRowsResponse = [ Row [ ] , google . bigtable . v2 . ReadRowsResponse ] ;
355354export type InsertRowsCallback = (
356- err : ServiceError | null ,
355+ err : ServiceError | PartialFailureError | null ,
357356 apiResponse ?: google . protobuf . Empty
358357) => void ;
359358export type InsertRowsResponse = [ google . protobuf . Empty ] ;
360359export type MutateCallback = (
361- err : ServiceError | null ,
360+ err : ServiceError | PartialFailureError | null ,
362361 apiResponse ?: google . protobuf . Empty
363362) => void ;
364363export type MutateResponse = [ google . protobuf . Empty ] ;
@@ -632,7 +631,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
632631 createReadStream ( opts ?: GetRowsOptions ) {
633632 const options = opts || { } ;
634633 const maxRetries = is . number ( this . maxRetries ) ? this . maxRetries ! : 3 ;
635- let activeRequestStream : common . AbortableDuplex ;
634+ let activeRequestStream : AbortableDuplex ;
636635 let rowKeys : string [ ] | null ;
637636 const ranges = options . ranges || [ ] ;
638637 let filter : { } | null ;
@@ -1382,7 +1381,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
13821381 typeof optionsOrCallback === 'function' ? optionsOrCallback : cb ! ;
13831382 const options =
13841383 typeof optionsOrCallback === 'object' ? optionsOrCallback : { } ;
1385- const entries = ( arrify ( entriesRaw ) as Entry [ ] ) . reduce (
1384+ const entries : Entry [ ] = ( arrify ( entriesRaw ) as Entry [ ] ) . reduce (
13861385 ( a , b ) => a . concat ( b ) ,
13871386 [ ]
13881387 ) ;
@@ -1398,10 +1397,11 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
13981397 ) ;
13991398 const mutationErrorsByEntryIndex = new Map ( ) ;
14001399
1401- const onBatchResponse = ( err : ServiceError | null ) => {
1400+ const onBatchResponse = (
1401+ err : ServiceError | PartialFailureError | null
1402+ ) => {
14021403 if ( err ) {
1403- // The error happened before a request was even made, don't
1404- // retry.
1404+ // The error happened before a request was even made, don't retry.
14051405 callback ( err ) ;
14061406 return ;
14071407 }
@@ -1412,10 +1412,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
14121412
14131413 if ( mutationErrorsByEntryIndex . size !== 0 ) {
14141414 const mutationErrors = Array . from ( mutationErrorsByEntryIndex . values ( ) ) ;
1415- err = new common . util . PartialFailureError ( {
1416- errors : mutationErrors ,
1417- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1418- } as any ) as ServiceError ;
1415+ err = new PartialFailureError ( mutationErrors ) ;
14191416 }
14201417
14211418 callback ( err ) ;
@@ -1439,7 +1436,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
14391436 } ;
14401437
14411438 this . bigtable
1442- . request ( {
1439+ . request < google . bigtable . v2 . MutateRowsResponse > ( {
14431440 client : 'BigtableClient' ,
14441441 method : 'mutateRows' ,
14451442 reqOpts,
@@ -1878,3 +1875,26 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
18781875promisifyAll ( Table , {
18791876 exclude : [ 'family' , 'row' ] ,
18801877} ) ;
1878+
1879+ export interface GoogleInnerError {
1880+ reason ?: string ;
1881+ message ?: string ;
1882+ }
1883+
1884+ export class PartialFailureError extends Error {
1885+ errors ?: GoogleInnerError [ ] ;
1886+ constructor ( errors : GoogleInnerError [ ] ) {
1887+ super ( ) ;
1888+ this . errors = errors ;
1889+ this . name = 'PartialFailureError' ;
1890+ let messages = errors . map ( e => e . message ) ;
1891+ if ( messages . length > 1 ) {
1892+ messages = messages . map ( ( message , i ) => ` ${ i + 1 } . ${ message } ` ) ;
1893+ messages . unshift (
1894+ 'Multiple errors occurred during the request. Please see the `errors` array for complete details.\n'
1895+ ) ;
1896+ messages . push ( '\n' ) ;
1897+ }
1898+ this . message = messages . join ( '\n' ) ;
1899+ }
1900+ }
0 commit comments