Skip to content

Corrupted settings can crash doq on launch #13

@juarezr

Description

@juarezr

bug: doq stopped working with previously corrupted settings

Suddenly the doq stopped working for me in Firefox. However, it still worked on Chromium.

After some debugging, I've found that the cause was a previously stored setting scheme that not matched the colorSchemes anymore.

Steps to Reproduce

I've compared the following pages:

  1. Example viewer linked from the doqment repository front page.
  2. Showing the same PDF of the example viewer in another Firefox tab using plain pdf.js without doqment extension installed.

Debugger Output

viewer.html
Uncaught (in promise) TypeError: scheme is undefined
    updateColorScheme https://shivaprsd.github.io/doq-demo/addon/doq.js:283
    updateReaderState https://shivaprsd.github.io/doq-demo/addon/doq.js:277
    load https://shivaprsd.github.io/doq-demo/addon/doq.js:83
    doqInit https://shivaprsd.github.io/doq-demo/addon/doq.js:16
doq.js:283:9
PDF 110dd61fd57444010b1ab5ff38782f0f [1.4 pdfeTeX-1.21a / TeX] (PDF.js: 2.13.216) app.js:1530:12

Call Stack

  updateColorScheme(index) {                   // index == 3
    const scheme = this.colorSchemes[index];   // this.colorSchemes == [{"Safari"}, {"Solarized"}] == 2 items
    if (!scheme.tones || !scheme.tones.length) // scheme === undefined --> Exception above
      return;
    ...
  },

Property Values

I've got these value inspecting variables inside the DevTools.

this.preferences

{
    flags: {
      ​​imagesOn: true,
      ​​shapesOn: true
    },
    ​​scheme: 3,  // <- does'nt matches this.colorSchemestone: "2",
    theme: "dark"
}

localStorage.getItem('doq.preferences.dark')

{"scheme":3,"tone":"2","flags":{"shapesOn":true,"imagesOn":true}}

this.colorSchemes

Array [ {}, {} ]
    0: Object { name: "Safari", tones: (4) [], colors: [] }
        colors: Array []
        name: "Safari"
        tones: Array(4) [ {}, {}, {},  ]
            ​​0: Object { name: "White", background: "#FFFFFF", foreground: "#1B1B1B",  }
            ​​​1: Object { name: "Sepia", background: "#F8F1E3", foreground: "#4F321C",  }
            ​​​2: Object { name: "Gray", background: "#4A4A4D", foreground: "#D7D7D8",  }
            ​​​3: Object { name: "Night", background: "#121212", foreground: "#B0B0B0",  }
            ​​​length: 4
    ​​​1: Object { name: "Solarized", tones: (2) [], accents: (8) [],  }
        accents: Array(8) [ "#B58900", "#CB4B16", "#DC322F",  ]
        colors: Array(8) [ {}, {}, {},  ]
        name: "Solarized"
        tones: Array [ {}, {} ]
            ​​​0: Object { name: "Light", background: "#FDF6E3", foreground: "#657B83",  }
            ​​​1: Object { name: "Dark", background: "#002B36", foreground: "#839496",  }
            ​​​length: 2
    ​​​length: 2

Patch to fix the issue

This makes the code more reliable on bad/corrupted settings:

  updateColorScheme(index) {
    const scheme = this.colorSchemes[index];
--    if (!scheme.tones || !scheme.tones.length)
++    if (!scheme || !scheme.tones || !scheme.tones.length)
      return;
    ...
  },

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions