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

Uncaught asynchronous error #410

Closed
edwardsph opened this issue Aug 15, 2022 · 0 comments
Closed

Uncaught asynchronous error #410

edwardsph opened this issue Aug 15, 2022 · 0 comments

Comments

@edwardsph
Copy link

There is a problem with an uncaught asynchronous error in the needle library which crashes the whole node process. Can you fix this to throw an error in the callback instead of crashing the process.

The short example below demonstrates the problem and I tried both approaches to called needle.

const needle = require('needle');
const url = 'https://wayback.archive-it.org/3259/20160921140616/https://www.arc.gov/research/MapsofAppalachia.asp?MAP_ID=11';
const options = {
        user_agent: 'user_agent',
        follow_max: 8,
        response_timeout: 3000,
        auth: 'auto',
        headers: {}
}

test(url, options).then((msg) => {
    console.log(msg);
    process.exit(0)
});

function test(url, options) {
  return new Promise((resolve, reject) => {
    needle.head(url, options, (error, res) => {
      console.log('res' + res)
      console.log('error' + error);
      resolve(error, res)
    })
  })
}

function test2(url, options) {
  return needle('head', url, options)
  .then(function(resp) {
    console.log('res' + resp)
  })
  .catch(function(err) {
      console.log('error' + err);
  });
}

The problem is the content type header: content-type: text/html; charset=maccentraleurope

.../node_modules/needle/node_modules/iconv-lite/lib/index.js:104
                throw new Error("Encoding not recognized: '" + encoding + "' (searched as: '"+enc+"')");
                ^

Error: Encoding not recognized: 'maccentraleurope' (searched as: 'maccentraleurope')
    at Object.getCodec (.../node_modules/needle/node_modules/iconv-lite/lib/index.js:104:23)
    at Object.getDecoder (.../node_modules/needle/node_modules/iconv-lite/lib/index.js:125:23)
    at Object.decodeStream (.../node_modules/needle/node_modules/iconv-lite/lib/index.js:156:55)
    at StreamDecoder._transform (.../node_modules/needle/lib/decoder.js:39:26)
    at StreamDecoder.Transform._read (_stream_transform.js:190:10)
    at StreamDecoder.Transform._write (_stream_transform.js:178:12)
    at doWrite (_stream_writable.js:415:12)
    at writeOrBuffer (_stream_writable.js:399:5)
    at StreamDecoder.Writable.write (_stream_writable.js:299:11)
    at IncomingMessage.ondata (_stream_readable.js:710:20)
    at IncomingMessage.emit (events.js:203:15)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at IncomingMessage.Readable.push (_stream_readable.js:224:10)
    at HTTPParser.parserOnBody (_http_common.js:124:22)
    at TLSSocket.socketOnData (_http_client.js:451:20)
    at TLSSocket.emit (events.js:198:13)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at TLSSocket.Readable.push (_stream_readable.js:224:10)
    at TLSWrap.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
@tomas tomas closed this as completed in f552069 Nov 17, 2022
tomas added a commit that referenced this issue Nov 17, 2022
Don't explode or unknown encodings. Fixes #410
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant