flatstr: SyntaxError: Unexpected token %
Hi, We are using Pino logger on our app which recently started producing error while printing logs. It internally uses flatstr for printing logs.
And it seems the last commit is causing this due. The issue is due to % character before FlattenString call.
I locally overrode the package & added some console logs in catch blocks to see how its flowing. I tried to simulate this locally using below & was able to replicate that: This is my main file (index.js)
var flt = require('./flatstr');
var str = 111;
console.log('the str - ', str);
var flattened = flt(str);
console.log('the flat str - ', flattened);
& changed the module’s index.js as below:
'use strict'
try {
var flatstr = Function('s', 'return typeof s === "string" ? %FlattenString(s) : s')
} catch (e) {
console.log('error1 ', e);
try {
var v8 = require('v' + '8')
v8.setFlagsFromString('--allow-natives-syntax')
var flatstr = Function('s', 'return typeof s === "string" ? %FlattenString(s) : s')
v8.setFlagsFromString('--no-allow-natives-syntax')
} catch (e) {
console.log('error2 ', e);
var flatstr = function flatstr(s) {
Number(s)
return s
}
}
}
module.exports = flatstr
Eventually the code falls back to last catch block where it just runs Number(s).
The output I see after running is below:
C:\v8test>node index.js
error1 SyntaxError: Unexpected token %
at Function (<anonymous>)
at Object.<anonymous> (C:\v8test\flatstr\index.js:4:17)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\v8test\index.js:1:73)
the str - 111
the flat str - 111
C:\v8test>
When I removed the % it worked without any exceptions. Can you please help?
Thanks, Nilesh
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 31 (8 by maintainers)
Commits related to this issue
- Update package-lock for new version of flatstr Should resolve the issue https://github.com/davidmarkclements/flatstr/issues/5 — committed to flytaly/feeddt by flytaly 5 years ago
It works, thanks!
flatstr was 1.0.9.
Edit:
In case whole shebang is useful for you:
I have updated dependencies and am now at 1.0.10. I’ll update if the issue resurfaces.