Skip to content

Filename is duplicated for errors created by path.buildCodeFrameError in 7.6.3 #10531

@coreyfarrell

Description

@coreyfarrell

Bug Report

Input Code

const path = require('path');
const {transformSync} = require('@babel/core');

transformSync('', {
	filename: path.resolve('filename.js'),
	plugins: [
		() => ({
			visitor: {
				Program(path) {
					throw path.buildCodeFrameError('example error');
				}
			}
		})
	]
});

Expected behavior/code
The first line of error.message should be /path/to/filename.js: example error

Current Behavior
The first line of error.message is /path/to/filename.js: /path/to/filename.js: example error

Babel Configuration (.babelrc, package.json, cli command)

None / see code.

Environment

  • Babel version(s): 7.6.3
  • Node/npm version: node 8+
  • OS: all
  • Monorepo: no
  • How you are using Babel: API

Possible Solution
Since packages/babel-core/src/transformation/index.js now prepends the error with the message maybe path.buildCodeFrameError should not do the same.

Additional context/Screenshots
Introduced by #10511. CC @JLHwung

Metadata

Metadata

Assignees

Labels

Has PRi: regressionoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions