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

Invalid Avro header does not raise error event #448

Open
craxal opened this issue Jan 31, 2024 · 1 comment
Open

Invalid Avro header does not raise error event #448

craxal opened this issue Jan 31, 2024 · 1 comment

Comments

@craxal
Copy link

craxal commented Jan 31, 2024

I discovered some mysterious behavior while using BlockDecoder. If the header is invalid (!tap.isVaid()), the stream does not raise an error event. Instead, it just returns.

This was confusing, because I was expecting an error event that I could process. I can work around this by listening for the "metadata" event and storing the parsed schema in a variable then testing to see if this variable is defined when the stream ends.

I'm not sure if this is intended behavior, but I would prefer if any invalid input would raise an error that can be handled rather than silently completing.

@mtth
Copy link
Owner

mtth commented Feb 13, 2024

Agreed that it's surprising behavior for the stream to not emit an error if it is ended without a valid header. (Until that happens, the tap.isValid return on failed check is expected: it just means the header is missing data.)

Until this is fixed, your workaround sounds right. To contain complexity on your end (and make migration easier later on) you could isolate the logic in a thin factory function. Something like (untested):

function newBlockDecoder(...args) {
  let truncated = true;
  return new avro.streams.BlockDecoder(...args)
    .on('finish', function () { if (truncated) { this.emit('error', new Error('Invalid header')); }})
    .on('metadata', () => { truncated = false; });
}

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

2 participants