-
Notifications
You must be signed in to change notification settings - Fork 14
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
How to catch parsing errors #10
Comments
On debugging I found it encounters the |
Could you provide some example data? Using string chunks is usually the easiest in order to debug: import {createParser} from 'eventsource-parser'
const parser = createParser((event) => {
console.log('event', event)
})
const chunks = [
'data: hello\n\n',
'data: world\n\n',
'event: custom\n',
'id: abc123\n',
'data: event\n\n',
]
for (const str of chunks) {
console.log('chunk', JSON.stringify(str))
parser.feed(str)
} Output:
|
@rexxars As I said my example data isn't valid format starting with
|
I don't see you mentioning anything about invalid data, but fair enough - thanks for clarifying. |
I guess I meant it by explaining the debugging steps especially Anyways lets keep it as a priority issue for next release. Throwing all invalid cases as exception in loud and clear manner is a must have for any library in today's world where projects depend on hundreds of libraries. I kept hunting for hours to figure out which library is making it go in infinite loop . By the way this is a very nice lib, it eased my parsing headache, we should always thank people of |
This is my code, const textDecoder = new TextDecoder()
let eventSourceParser: EventSourceParser
return new TransformStream({
async start(controller) {
eventSourceParser = createParser(
(event: ParsedEvent | ReconnectInterval) => {
console.log(event)
},
)
},
transform(chunk) {
const value = textDecoder.decode(chunk)
// the value is a string like:
// {
// "error": {
// "message": "An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. The following tool_call_ids did not have response messages: call_FwpczVWzU3oIb0tSLiCHOt2z",
// "type": "invalid_request_error",
// "param": "messages",
// "code": null
// }
// }
eventSourceParser.feed(value)
},
}) |
Just released v3.0.0 with support for |
How do I catch in such scenarios:
str
is rightly printed but when it entersparser.feed
, it gets stuck and never returns; nor does it throw any errors.And hence it never reaches
console.log("event", event)
evenresp
is the respose object andonMessage
is just a functionThe text was updated successfully, but these errors were encountered: