in v2/spanner-common/src/main/java/com/google/cloud/teleport/v2/spanner/migrations/exceptions/SpannerExceptionParser.java [52:130]
public static SpannerMigrationException parse(SpannerException exception) {
ErrorCode errorCode =
switch (exception.getErrorCode()) {
case UNIMPLEMENTED -> ErrorCode.SPANNER_UNIMPLEMENTED;
case UNAUTHENTICATED -> ErrorCode.SPANNER_UNAUTHENTICATED;
case PERMISSION_DENIED -> ErrorCode.SPANNER_PERMISSION_DENIED;
case UNAVAILABLE -> ErrorCode.SPANNER_UNAVAILABLE;
case OUT_OF_RANGE -> {
if (containsIgnoreCase(exception.getMessage(), CHECK_CONSTRAINT_VIOLATION_1)
&& containsIgnoreCase(exception.getMessage(), CHECK_CONSTRAINT_VIOLATION_2)) {
yield ErrorCode.SPANNER_CHECK_CONSTRAINT_VIOLATION;
} else {
yield ErrorCode.SPANNER_OUT_OF_RANGE;
}
}
case INVALID_ARGUMENT -> {
if (containsIgnoreCase(exception.getMessage(), CELL_VALUE_TOO_LARGE)) {
yield ErrorCode.SPANNER_VALUE_TOO_LARGE;
} else {
yield ErrorCode.SPANNER_INVALID_ARGUMENT;
}
}
case NOT_FOUND -> {
if (containsIgnoreCase(exception.getMessage(), TABLE_NOT_FOUND)) {
yield ErrorCode.SPANNER_TABLE_NOT_FOUND;
} else if (containsIgnoreCase(exception.getMessage(), COLUMN_NOT_FOUND)) {
yield ErrorCode.SPANNER_COLUMN_NOT_FOUND;
} else if (containsIgnoreCase(exception.getMessage(), PARENT_NOT_FOUND_1)
&& containsIgnoreCase(exception.getMessage(), PARENT_NOT_FOUND_2)) {
yield ErrorCode.SPANNER_PARENT_NOT_FOUND;
} else {
yield ErrorCode.SPANNER_NOT_FOUND;
}
}
case ALREADY_EXISTS -> {
if (containsIgnoreCase(exception.getMessage(), UNIQUE_INDEX_VIOLATION)) {
yield ErrorCode.SPANNER_UNIQUE_INDEX_VIOLATION;
} else {
yield ErrorCode.SPANNER_ALREADY_EXISTS;
}
}
case FAILED_PRECONDITION -> {
if (containsIgnoreCase(exception.getMessage(), DATATYPE_MISMATCH)) {
yield ErrorCode.SPANNER_INVALID_VALUE;
} else if (containsIgnoreCase(exception.getMessage(), NOT_NULL_VIOLATION)) {
yield ErrorCode.SPANNER_NULL_VALUE_FOR_REQUIRED_COLUMN;
} else if (containsIgnoreCase(exception.getMessage(), WRITE_TO_GENERATED_COLUMN)) {
yield ErrorCode.SPANNER_WRITE_TO_GENERATED_COLUMN_NOT_ALLOWED;
} else if (containsIgnoreCase(
exception.getMessage(), GENERATED_PK_NOT_FULLY_SPECIFIED_1)
&& containsIgnoreCase(exception.getMessage(), GENERATED_PK_NOT_FULLY_SPECIFIED_2)) {
yield ErrorCode.SPANNER_DEPENDENT_COLUMN_NOT_SPECIFIED;
} else if (containsIgnoreCase(exception.getMessage(), WRONG_NUMBER_OF_KEY_PARTS)) {
yield ErrorCode.SPANNER_WRONG_NUMBER_OF_KEY_PARTS;
} else if (containsIgnoreCase(exception.getMessage(), FK_VIOLATION_CHILD_INSERT_1)
&& containsIgnoreCase(exception.getMessage(), FK_VIOLATION_CHILD_INSERT_2)) {
yield ErrorCode.SPANNER_FOREIGN_KEY_CONSTRAINT_VIOLATION;
} else if (containsIgnoreCase(exception.getMessage(), FK_VIOLATION_PARENT_DELETE)) {
yield ErrorCode.SPANNER_FOREIGN_KEY_CONSTRAINT_VIOLATION;
} else if (containsIgnoreCase(exception.getMessage(), FK_VIOLATION_PARENT_UPDATE)) {
yield ErrorCode.SPANNER_FOREIGN_KEY_CONSTRAINT_VIOLATION;
} else {
yield ErrorCode.SPANNER_UNKNOWN_ERROR;
}
}
case UNKNOWN -> {
if (containsIgnoreCase(exception.getMessage(), DUPLICATE_COLUMN)) {
yield ErrorCode.SPANNER_DUPLICATE_COLUMN;
} else {
yield ErrorCode.SPANNER_UNKNOWN_ERROR;
}
}
case DEADLINE_EXCEEDED -> ErrorCode.SPANNER_DEADLINE_EXCEEDED;
case RESOURCE_EXHAUSTED -> ErrorCode.SPANNER_RESOURCE_EXHAUSTED;
case ABORTED -> ErrorCode.SPANNER_TRANSACTION_ABORTED;
default -> ErrorCode.SPANNER_UNKNOWN_ERROR;
};
return new SpannerMigrationException(errorCode, exception.getMessage(), exception);
}