Closed6

PartialFailureError at Table._insert

ツルオカツルオカ

Cloud FunctionsでBigQueryにInsertするだけの処理でエラーが発生する

⚠  functions: PartialFailureError
    at Table._insert (xxx/node_modules/@google-cloud/bigquery/build/src/table.js:1717:19)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Table._insertWithRetry ((xxx/node_modules/@google-cloud/bigquery/build/src/table.js:1654:24)
    at async Table._insertAndCreateTable ((xxx/node_modules/@google-cloud/bigquery/build/src/table.js:1616:20)
transaction.ts
export async function transaction(data: string) {
  const row = [{ insert_at: new Date(), data: data }]
  await bigquery.dataset(_dataset).table(_table).insert(row)
}
ツルオカツルオカ

このようなエラーハンドリングを書くとより詳細なログが得られる。
https://github.com/googleapis/nodejs-bigquery/issues/612#issuecomment-838446559

try {
  await table.insert([row], {
    skipInvalidRows: false,
    ignoreUnknownValues: false,
    createInsertId: false,
    raw: true,
  });
} catch (e) {
  logger.error(e);
  if (e.name === 'PartialFailureError') {
    for (const err of (e.errors as { errors: { message: string, reason: string }[], row: any }[])) {
      logger.error(err);
    }
  } else {
    logger.error(e);
  }
ツルオカツルオカ

普通に型が誤っていた

"message":"Array specified for non-repeated field: entitlement_ids.","reason":"invalid"}

このスクラップは2021/10/27にクローズされました