Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide clear error message on missing xsltproc dependency #6674

Closed
derickl opened this issue Oct 12, 2020 · 11 comments
Closed

Provide clear error message on missing xsltproc dependency #6674

derickl opened this issue Oct 12, 2020 · 11 comments
Assignees
Labels
API Affects the API service Help wanted Good for first time contributions Type: Improvement Make something better
Milestone

Comments

@derickl
Copy link
Member

derickl commented Oct 12, 2020

API fails with a cryptic error when xsltproc is missing

2020-10-12 13:55:43 DEBUG: Generating html and xml model for enketo form "form:contact:clinic:create"
2020-10-12 13:55:43 ERROR: Fatal error initialising medic-api
2020-10-12 13:55:43 ERROR: { Error: write EPIPE
    at afterWriteDispatched (internal/stream_base_commons.js:78:25)
    at writeGeneric (internal/stream_base_commons.js:73:3)
    at Socket._writeGeneric (net.js:714:5)
    at Socket._write (net.js:726:8)
    at doWrite (_stream_writable.js:415:12)
    at writeOrBuffer (_stream_writable.js:399:5)
    at Socket.Writable.write (_stream_writable.js:299:11)
    at Promise (/home/ojwang/.horticulturalist/deployments/medic-api/md5-P30WflsoaGDhDW7mhDdK8w==/src/services/generate-xform.js:28:20)
    at new Promise (<anonymous>)
    at transform (/home/ojwang/.horticulturalist/deployments/medic-api/md5-P30WflsoaGDhDW7mhDdK8w==/src/services/generate-xform.js:21:10)
  [stack]:
   'Error: write EPIPE\n    at afterWriteDispatched (internal/stream_base_commons.js:78:25)\n    at writeGeneric (internal/stream_base_commons.js:73:3)\n    at Socket._writeGeneric (net.js:714:5)\n    at Socket._write (net.js:726:8)\n    at doWrite (_stream_writable.js:415:12)\n    at writeOrBuffer (_stream_writable.js:399:5)\n    at Socket.Writable.write (_stream_writable.js:299:11)\n    at Promise (/home/ojwang/.horticulturalist/deployments/medic-api/md5-P30WflsoaGDhDW7mhDdK8w==/src/services/generate-xform.js:28:20)\n    at new Promise (<anonymous>)\n    at transform (/home/ojwang/.horticulturalist/deployments/medic-api/md5-P30WflsoaGDhDW7mhDdK8w==/src/services/generate-xform.js:21:10)',
  [message]: 'write EPIPE',
  errno: 'EPIPE',
  code: 'EPIPE',
  syscall: 'write',
  [Symbol(kExpandStackSymbol)]:
   { [Function: bound enhanceStackTrace] [length]: 0, [name]: 'bound enhanceStackTrace' } }
2020-10-12 13:55:49 INFO: Waiting for API to be ready...

I believe we should explicitly mention that in the error

Related to #6455

This was experienced in 3.10

@derickl derickl added the Type: Improvement Make something better label Oct 12, 2020
@MaxDiz MaxDiz added this to Needs triage in Core Engineers Backlog via automation Oct 12, 2020
@MaxDiz MaxDiz added the API Affects the API service label Oct 12, 2020
@garethbowen garethbowen added the Help wanted Good for first time contributions label Dec 16, 2020
@garethbowen garethbowen added this to the 3.13.0 - DRAFT milestone Jun 2, 2021
@michaelkohn michaelkohn added this to Ready for dev in Allies Workstream - DEPRECATED via automation Jun 29, 2021
@mrsarm mrsarm self-assigned this Sep 1, 2021
@mrsarm mrsarm moved this from Ready for dev to Dev in progress in Allies Workstream - DEPRECATED Sep 8, 2021
@mrsarm mrsarm moved this from Needs triage to Scheduled in Core Engineers Backlog Sep 8, 2021
@craig-landry craig-landry modified the milestones: 3.13.0, 3.14.0 Sep 15, 2021
@craig-landry
Copy link
Member

This looks like it's almost done so I'm leaving it for 3.13.0 since we have other parallel things going on still anyway. It shouldn't block at 3.13.0 release though, so I'll bump it to 3.14.0 later if it comes to it.

@mrsarm mrsarm moved this from Dev in progress to Ready for AT in Allies Workstream - DEPRECATED Sep 16, 2021
@mrsarm
Copy link
Contributor

mrsarm commented Sep 17, 2021

I have moved to AT but forgot to confirm that is ready: PR #7301 , branch 6674-fix-xsltproc-error.

Test steps

  1. Uninstall or just rename the xsltproc command
  2. Start API. The error Unable to continue execution, check that 'xsltproc' command is available. stops the API execution
  3. Restore the command and restart the API: the process starts OK

Another use case is instead of remove or rename the command just change the permissions access to not allow the API to execute it (chmod).

@ngaruko ngaruko moved this from Ready for AT to AT in progress in Allies Workstream - DEPRECATED Sep 20, 2021
@ngaruko ngaruko self-assigned this Sep 20, 2021
@ngaruko
Copy link
Contributor

ngaruko commented Sep 20, 2021

@mrsarm , the try...catch block does not seem to work on my machine. I just renamed the dependency to something that does not exist xsltproc3 and ran the API, and got this error.

2021-09-20 21:38:51 ERROR:   Error: Error: write EPIPE
    at afterWriteDispatched (internal/stream_base_commons.js:156:25)
    at writeGeneric (internal/stream_base_commons.js:147:3)
    at Socket._writeGeneric (net.js:787:11)
    at Socket._write (net.js:799:8)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at Socket.Writable.write (internal/streams/writable.js:303:10)
    at /Users/bede/Medic/cht-core/api/src/services/generate-xform.js:30:22
    at new Promise (<anonymous>)
    at transform (/Users/bede/Medic/cht-core/api/src/services/generate-xform.js:22:10)
    at generateForm (/Users/bede/Medic/cht-core/api/src/services/generate-xform.js:74:10) {
  [stack]: 'Error: write EPIPE\n' +
    '    at afterWriteDispatched (internal/stream_base_commons.js:156:25)\n' +
    '    at writeGeneric (internal/stream_base_commons.js:147:3)\n' +
    '    at Socket._writeGeneric (net.js:787:11)\n' +
    '    at Socket._write (net.js:799:8)\n' +
    '    at writeOrBuffer (internal/streams/writable.js:358:12)\n' +
    '    at Socket.Writable.write (internal/streams/writable.js:303:10)\n' +
    '    at /Users/bede/Medic/cht-core/api/src/services/generate-xform.js:30:22\n' +
    '    at new Promise (<anonymous>)\n' +
    '    at transform (/Users/bede/Medic/cht-core/api/src/services/generate-xform.js:22:10)\n' +
    '    at generateForm (/Users/bede/Medic/cht-core/api/src/services/generate-xform.js:74:10)',
  [message]: 'write EPIPE',
  errno: -32,
  code: 'EPIPE',
  syscall: 'write',
  [Symbol(kEnhanceStackBeforeInspector)]: [Function: bound enhanceStackTrace] {
    [length]: 0,
    [name]: 'bound enhanceStackTrace'
  }
} 

Basically the code in the catch block does not seem to have been executed. However, if I use xsltproc.stdin.on('error',, it seems to catch that EPIPE error like so:

  xsltproc.stdin.on('error', (error) => {
      if (error.code === 'EPIPE') {
        const errMsg = `Unable to continue execution, check that '${XSLTPROC_CMD}' command is available.`;
        logger.error(errMsg);
        return reject(new Error(errMsg));
      }
    });

and the output for this:

2021-09-20 21:52:01 DEBUG: Generating html and xml model for enketo form "form:contact:clinic:create" 
2021-09-20 21:52:01 ERROR: spawn xsltproc3 ENOENT Error: spawn xsltproc3 ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    at onErrorNT (internal/child_process.js:467:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
2021-09-20 21:52:01 ERROR: Unable to continue execution, check that 'xsltproc3' command is available. 
2021-09-20 21:52:01 ERROR: spawn xsltproc3 ENOENT Error: spawn xsltproc3 ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    at onErrorNT (internal/child_process.js:467:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
2021-09-20 21:52:01 ERROR: Unable to continue execution, check that 'xsltproc3' command is available. 
2021-09-20 21:52:01 ERROR: Fatal error initialising medic-api 
2021-09-20 21:52:01 ERROR: Error: Child process errored attempting to transform xml
    at ChildProcess.<anonymous> (/Users/bede/Medic/cht-core/api/src/services/generate-xform.js:65:21)
    at ChildProcess.emit (events.js:400:28)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    at onErrorNT (internal/child_process.js:467:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  [stack]: 'Error: Child process errored attempting to transform xml\n' +
    '    at ChildProcess.<anonymous> (/Users/bede/Medic/cht-core/api/src/services/generate-xform.js:65:21)\n' +
    '    at ChildProcess.emit (events.js:400:28)\n' +
    '    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)\n' +
    '    at onErrorNT (internal/child_process.js:467:16)\n' +
    '    at processTicksAndRejections (internal/process/task_queues.js:82:21)',
  [message]: 'Child process errored attempting to transform xml'
} 

Did you wanna have a look and see why this is? Thanks.

@ngaruko
Copy link
Contributor

ngaruko commented Sep 21, 2021

LG atm. Must have to do with the operating system, as it seems to behave differently on mac than on Linux.

**2021-09-21 22:31:01 ERROR: Unable to continue execution, check that 'xsltproc7' command is available.** 
2021-09-21 22:31:01 ERROR: spawn xsltproc7 ENOENT Error: spawn xsltproc7 ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    at onErrorNT (internal/child_process.js:467:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
**2021-09-21 22:31:01 ERROR: Unable to continue execution, check that 'xsltproc7' command is available.** 
2021-09-21 22:31:01 ERROR: Fatal error initialising medic-api 

Please feel free to merge @mrsarm .

@ngaruko ngaruko moved this from AT in progress to Ready to merge in Allies Workstream - DEPRECATED Sep 21, 2021
@mrsarm mrsarm closed this as completed Sep 22, 2021
Core Engineers Backlog automation moved this from Scheduled to Done Sep 22, 2021
Allies Workstream - DEPRECATED automation moved this from Ready to merge to Done Sep 22, 2021
@mrsarm
Copy link
Contributor

mrsarm commented Sep 22, 2021

Reopening the issue because the workaround only solved the problem for Node v10 and v12. Node v8 and v14+ requires other 2 approaches that I'm addressing in #7335

@mrsarm mrsarm reopened this Sep 22, 2021
Allies Workstream - DEPRECATED automation moved this from Done to Dev in progress Sep 22, 2021
@mrsarm mrsarm removed this from the 3.13.0 milestone Sep 22, 2021
@mrsarm mrsarm added this to the 3.14.0 milestone Sep 22, 2021
@mrsarm mrsarm moved this from Done to Scheduled in Core Engineers Backlog Sep 22, 2021
@mrsarm
Copy link
Contributor

mrsarm commented Sep 24, 2021

Ready for AT, PR #7335 , branch xsltproc-fix-error-catch.

The scenarios to tests are the same than before, but now we should test against all the versions of Node we support (v8, v10, v12, v14 and v16).

@mrsarm mrsarm moved this from Dev in progress to Ready for AT in Allies Workstream - DEPRECATED Sep 24, 2021
@newtewt
Copy link
Contributor

newtewt commented Sep 30, 2021

@ngaruko can you work this secondary fix. I don't have the multiple operating systems you've defined.

@mrjones-plip
Copy link
Contributor

@newtewt - lemme know if MacOS testing is what's needed and @ngaruko isn't avail.

@ngaruko
Copy link
Contributor

ngaruko commented Oct 4, 2021

@newtewt I think it was not an OS issue but a node version issue. With node 8, the api crash but there the human readable error does not show. With node 14, I was able to see the error with code EPIPE thrown.

@ngaruko
Copy link
Contributor

ngaruko commented Oct 5, 2021

I have verified that it works on all supported versions of node (v8 to v14). To help test with ease, I stripped the build.yml to only run a modified version of the file: node api/src/services/generate-xform.js and created 4 jobs, for the 4 node versions
with this build for ubuntu and this for macOs.
image

Feel free to merge @mrsarm

@ngaruko ngaruko moved this from Ready for AT to AT in progress in Allies Workstream - DEPRECATED Oct 5, 2021
@ngaruko ngaruko moved this from AT in progress to Ready to merge in Allies Workstream - DEPRECATED Oct 5, 2021
@mrsarm
Copy link
Contributor

mrsarm commented Oct 5, 2021

Nice trick @ngaruko 👏 Thanks !

@mrsarm mrsarm closed this as completed Oct 5, 2021
Core Engineers Backlog automation moved this from Scheduled to Done Oct 5, 2021
Allies Workstream - DEPRECATED automation moved this from Ready to merge to Done Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Affects the API service Help wanted Good for first time contributions Type: Improvement Make something better
Projects
No open projects
Development

No branches or pull requests

8 participants