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

Bug fix/writable stream validator #242

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Bluebberies
Copy link

Bug Explanation: Invalid Stream Type for Ora Spinner

Summary

The ora library requires that the stream option passed during spinner initialization be a writable stream. If a non-writable stream or an object that lacks a write method is provided, it throws a TypeError.

Reproduction Steps

  1. Import the ora library.
  2. Create an object that does not have a write method (e.g., a plain object or a read-only stream).
  3. Attempt to initialize ora with this object as the stream option.

Example Code

const ora = require('ora');
const myStream = {}; // Non-writable stream
const spinner = ora({ stream: myStream });

The above code will return an unhandled exception 


**Fix**

if (options?.stream && typeof options.stream.write !== "function") {
    throw new TypeError("Stream must be a writable stream");
}

This check indicates that the ora spinner accepts a stream option, which should be a writable stream. The bug arises when the provided stream option does not conform to this expectation. A common real-world scenario that can lead to this issue is passing a non-writable stream (like a read-only stream) to the ora instance.

const nonWritableStream = {};

const error = t.throws(_ => ora({stream: nonWritableStream}), {
instanceOf: TypeError,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message should be asserted here too.

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

Successfully merging this pull request may close these issues.

2 participants