markushedvall / plantuml-viewer

PlantUML Viewer package for Atom
MIT License
61 stars 14 forks source link

Uncaught TypeError: savePath.lastIndexOf is not a function #54

Open TakeshiHoshina opened 4 years ago

TakeshiHoshina commented 4 years ago

[Enter steps to reproduce:]

  1. ...
  2. ...

Atom: 1.52.0 x64 Electron: 6.1.12 OS: Mac OS X 10.15.5 Thrown From: plantuml-viewer package 0.7.2

Stack Trace

Uncaught TypeError: savePath.lastIndexOf is not a function

At /Users/takeshihoshina1/.atom/packages/plantuml-viewer/lib/plantuml-viewer-view.js:189

TypeError: savePath.lastIndexOf is not a function
    at saveAs (/packages/plantuml-viewer/lib/plantuml-viewer-view.js:189:48)
    at /packages/plantuml-viewer/lib/plantuml-viewer-view.js:103:7)
    at CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app/static/<embedded>:11:349963)
    at KeymapManager.dispatchCommandEvent (/Applications/Atom.app/Contents/Resources/app/static/<embedded>:11:1231297)
    at KeymapManager.handleKeyboardEvent (/Applications/Atom.app/Contents/Resources/app/static/<embedded>:11:1227431)
    at WindowEventHandler.handleDocumentKeyEvent (/Applications/Atom.app/Contents/Resources/app/static/<embedded>:11:284820)

Commands

     -2:46.2.0 core:backspace (input.hidden-input)
     -1:56.3.0 plantuml-preview:toggle (input.hidden-input)
  3x -1:37.7.0 platformio-ide-terminal:paste (div.terminal)
     -0:59.1.0 core:save (div.plantuml-viewer.native-key-bindings)

Non-Core Packages

atom-beautify 0.33.4 
file-icons 2.1.43 
highlight-selected 0.17.0 
language-plantuml 0.2.0 
pigments 0.40.6 
plantuml-preview 0.12.10 
plantuml-viewer 0.7.2 
platformio-ide-terminal 2.10.0 
project-manager 3.3.8 
xanadiu commented 4 years ago

(I encountered this error, too)

Steps to reproduce:

  1. Toggle the Plantuml Viewer in Atom
  2. Focus the Plantuml Viewer
  3. Try to save the image
  4. The error occurs while the dialogue for the save location appears; saving is not possible

Atom: 1.52.0 x64 OS: macOS 10.15.7

nguyenquangson commented 3 years ago

I also like your error. You can fix that by following steps. C:\Users\XXXX.atom\packages\plantuml-viewer\lib\plantuml-viewer-view.js ① function saveAs () { ↓ async function saveAs () { ② var savePath = atom.showSaveDialogSync(options) ↓ const savePath = await atom.showSaveDialogSync(options) ③ last replare using savePath -> savePath.filePath

JerilynZ commented 3 years ago

I also like your error. You can fix that by following steps. C:\Users\XXXX.atom\packages\plantuml-viewer\lib\plantuml-viewer-view.js ① function saveAs () { ↓ async function saveAs () { ② var savePath = atom.showSaveDialogSync(options) ↓ const savePath = await atom.showSaveDialogSync(options) ③ last replare using savePath -> savePath.filePath

thank you for your share. It is useful. ③ should be: last, please replace "savePath" with "savePath.filePath", beside the "const savePath = await atom.showSaveDialogSync(options)"

triynko commented 3 years ago

Same error encountered. Jan 2021.

Pyponou commented 3 years ago

Same issue

Here is the fix made by @nguyenquangson , I put it here as I didn't understand the number 3 :

  async function saveAs () {
    var filters = [
      { name: 'Encapsulated PostScript (.eps)', extensions: ['eps'] },
      { name: 'Scalable Vector Graphics (.svg)', extensions: ['svg'] },
      { name: 'Portable Network Graphics (.png)', extensions: ['png'] }
    ]
    var filePath = editor.getPath().replace(/\.[^/.]+$/, '')
    var options = { defaultPath: filePath, filters: filters }
    const savePath = await atom.showSaveDialogSync(options)

    if (savePath.filePath) {
      var extension = savePath.filePath.substr(savePath.filePath.lastIndexOf('.') + 1)
      var fileStream = fs.createWriteStream(savePath.filePath)

      var plantumlOptions = {
        format: extension,
        include: includePath,
        dot: atom.config.get('plantuml-viewer.graphvizDotExecutable') || getDetectedPathFor('dot'),
        config: atom.config.get('plantuml-viewer.configFile'),
        charset: atom.config.get('plantuml-viewer.charset')
      }

      var gen = plantuml.generate(editor.getText(), plantumlOptions)
      gen.out.pipe(fileStream)
    }
  }