Skip to content

Commit

Permalink
Merge pull request mozilla#17979 from Snuffleupagus/image-errors-shor…
Browse files Browse the repository at this point in the history
…ter-msg

[api-minor] Remove the image-related error message prefixes
  • Loading branch information
timvandermeij authored Apr 22, 2024
2 parents c22e64c + 912b57b commit 335d839
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/core/jbig2.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { CCITTFaxDecoder } from "./ccitt.js";

class Jbig2Error extends BaseException {
constructor(msg) {
super(`JBIG2 error: ${msg}`, "Jbig2Error");
super(msg, "Jbig2Error");
}
}

Expand Down Expand Up @@ -2593,4 +2593,4 @@ class Jbig2Image {
}
}

export { Jbig2Image };
export { Jbig2Error, Jbig2Image };
4 changes: 2 additions & 2 deletions src/core/jpg.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { readUint16 } from "./core_utils.js";

class JpegError extends BaseException {
constructor(msg) {
super(`JPEG error: ${msg}`, "JpegError");
super(msg, "JpegError");
}
}

Expand Down Expand Up @@ -1580,4 +1580,4 @@ class JpegImage {
}
}

export { JpegImage };
export { JpegError, JpegImage };
4 changes: 2 additions & 2 deletions src/core/jpx.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import OpenJPEG from "../../external/openjpeg/openjpeg.js";

class JpxError extends BaseException {
constructor(msg) {
super(`JPX error: ${msg}`, "JpxError");
super(msg, "JpxError");
}
}

Expand Down Expand Up @@ -68,4 +68,4 @@ class JpxImage {
}
}

export { JpxImage };
export { JpxError, JpxImage };
9 changes: 6 additions & 3 deletions src/pdf.image_decoders.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import {
setVerbosityLevel,
VerbosityLevel,
} from "./shared/util.js";
import { Jbig2Image } from "./core/jbig2.js";
import { JpegImage } from "./core/jpg.js";
import { JpxImage } from "./core/jpx.js";
import { Jbig2Error, Jbig2Image } from "./core/jbig2.js";
import { JpegError, JpegImage } from "./core/jpg.js";
import { JpxError, JpxImage } from "./core/jpx.js";

/* eslint-disable-next-line no-unused-vars */
const pdfjsVersion =
Expand All @@ -31,8 +31,11 @@ const pdfjsBuild =

export {
getVerbosityLevel,
Jbig2Error,
Jbig2Image,
JpegError,
JpegImage,
JpxError,
JpxImage,
setVerbosityLevel,
VerbosityLevel,
Expand Down
6 changes: 5 additions & 1 deletion test/fuzz/jbig2_image.fuzz.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Jbig2Error,
Jbig2Image,
setVerbosityLevel,
VerbosityLevel,
Expand All @@ -7,9 +8,12 @@ import {
// Avoid unnecessary console "spam", by ignoring `info`/`warn` calls.
setVerbosityLevel(VerbosityLevel.ERRORS);

const ignored = ["Cannot read properties", "JBIG2 error"];
const ignored = ["Cannot read properties"];

function ignoredError(error) {
if (error instanceof Jbig2Error) {
return true;
}
return ignored.some(message => error.message.includes(message));
}

Expand Down
6 changes: 5 additions & 1 deletion test/fuzz/jpeg_image.fuzz.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
JpegError,
JpegImage,
setVerbosityLevel,
VerbosityLevel,
Expand All @@ -7,9 +8,12 @@ import {
// Avoid unnecessary console "spam", by ignoring `info`/`warn` calls.
setVerbosityLevel(VerbosityLevel.ERRORS);

const ignored = ["Cannot read properties", "JPEG error"];
const ignored = ["Cannot read properties"];

function ignoredError(error) {
if (error instanceof JpegError) {
return true;
}
return ignored.some(message => error.message.includes(message));
}

Expand Down
6 changes: 5 additions & 1 deletion test/fuzz/jpx_image.fuzz.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
JpxError,
JpxImage,
setVerbosityLevel,
VerbosityLevel,
Expand All @@ -7,9 +8,12 @@ import {
// Avoid unnecessary console "spam", by ignoring `info`/`warn` calls.
setVerbosityLevel(VerbosityLevel.ERRORS);

const ignored = ["Cannot read properties", "JPX error"];
const ignored = ["Cannot read properties"];

function ignoredError(error) {
if (error instanceof JpxError) {
return true;
}
return ignored.some(message => error.message.includes(message));
}

Expand Down
9 changes: 6 additions & 3 deletions test/unit/pdf.image_decoders_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import {
setVerbosityLevel,
VerbosityLevel,
} from "../../src/shared/util.js";
import { Jbig2Image } from "../../src/core/jbig2.js";
import { JpegImage } from "../../src/core/jpg.js";
import { JpxImage } from "../../src/core/jpx.js";
import { Jbig2Error, Jbig2Image } from "../../src/core/jbig2.js";
import { JpegError, JpegImage } from "../../src/core/jpg.js";
import { JpxError, JpxImage } from "../../src/core/jpx.js";

describe("pdfimage_api", function () {
it("checks that the *official* PDF.js-image decoders API exposes the expected functionality", async function () {
Expand All @@ -35,8 +35,11 @@ describe("pdfimage_api", function () {
// hence we copy the data to allow using a simple comparison below.
expect({ ...pdfimageAPI }).toEqual({
getVerbosityLevel,
Jbig2Error,
Jbig2Image,
JpegError,
JpegImage,
JpxError,
JpxImage,
setVerbosityLevel,
VerbosityLevel,
Expand Down

0 comments on commit 335d839

Please sign in to comment.