Skip to content

'box()' function does not work with a title >=2 chars longer than the content length #300

@GRyanParoz

Description

@GRyanParoz

Environment

Consola version 3.2.3

Tested using Bun v1.1.12 and Node.js 18.20.3 (Stackblitz)

Reproduction

https://stackblitz.com/edit/stackblitz-starters-zlz8zk?file=index.js

Describe the bug

If the box function from consola/utils (or consola.box) is called with a "title" option that contains a string 2 characters longer than the content itself, an error is thrown and the box is not drawn.

Additional context

The error is coming from String.repeat, seemingly because the number of repeated characters is calculated by subtracting the title length from the content length or something similar.

Logs

RangeError: String.prototype.repeat argument must be greater than or equal to 0 and not be Infinity
      at repeat (:1:21)
      at box (<private-project>/node_modules/consola/dist/utils.mjs:246:18)
      at previewJson (<private-project>/src/logger.ts:17:13)
      at <private-project>/src/deploy-schema.ts:23:5

Bun v1.1.12 (Linux x64)
error: script "schema:deploy" exited with code 1

-----

Error: repeat count must be non-negative
    at _evaluate (https://stackblitzstarterszlz8zk-vfqw.w-corp-staticblitz.com/blitz.12d46890.js:40:783715)

Node.js 18.20.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions