Skip to content

Commit

Permalink
Merge pull request #90 from ttsukagoshi/text-too-long
Browse files Browse the repository at this point in the history
Update error message for cells with too much text
  • Loading branch information
ttsukagoshi authored Jun 3, 2023
2 parents c772b7c + fcfbf78 commit 8797c83
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/sheetsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,15 @@ export function translateRange(): void {
if (cellValue === '') {
return '';
}
if (getBlobBytes(encodeURIComponent(cellValue)) > THRESHOLD_BYTES) {
const textBytes = getBlobBytes(encodeURIComponent(cellValue));
if (textBytes > THRESHOLD_BYTES) {
const cellValueString = cellValue.toString();
const truncatedCellValue = cellValueString.slice(
0,
Math.floor((cellValueString.length * THRESHOLD_BYTES) / textBytes)
);
throw new Error(
`[${ADDON_NAME}] Cell content is too long. Please consider splitting the content into multiple cells:\n${cellValue}`
`[${ADDON_NAME}] Cell content length exceeds Google's limits. Please consider splitting the content into multiple cells. The following is the estimated maximum length of the cell in question:\n${truncatedCellValue}\n\nPlease note that this is a rough estimate and that the actual acceptable text length might differ slightly.`
);
} else {
Utilities.sleep(1000); // Interval to avoid concentrated access to API
Expand Down

0 comments on commit 8797c83

Please sign in to comment.