Skip to content

Commit

Permalink
Correctly serialize ThrowableDiagnostic from transformers
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Jan 12, 2022
1 parent 1dd65a7 commit d9a55b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/core/core/src/Transformation.js
Expand Up @@ -26,9 +26,11 @@ import {Readable} from 'stream';
import nullthrows from 'nullthrows';
import logger, {PluginLogger} from '@parcel/logger';
import ThrowableDiagnostic, {
anyToDiagnostic,
errorToDiagnostic,
escapeMarkdown,
md,
type Diagnostic,
} from '@parcel/diagnostic';
import {SOURCEMAP_EXTENSIONS} from '@parcel/utils';
import {hashString} from '@parcel/hash';
Expand Down Expand Up @@ -84,7 +86,7 @@ export type TransformationOpts = {|

export type TransformationResult = {|
assets?: Array<AssetValue>,
error?: Error,
error?: Array<Diagnostic>,
configRequests: Array<ConfigRequest>,
invalidations: Array<RequestInvalidation>,
invalidateOnFileCreate: Array<InternalFileCreateInvalidation>,
Expand Down Expand Up @@ -197,7 +199,8 @@ export default class Transformation {
$$raw: true,
assets,
configRequests,
error,
// When throwing an error, this (de)serialization is done automatically by the WorkerFarm
error: error ? anyToDiagnostic(error) : undefined,
invalidateOnFileCreate: this.invalidateOnFileCreate,
invalidations: [...this.invalidations.values()],
devDepRequests,
Expand Down
3 changes: 2 additions & 1 deletion packages/core/core/src/requests/AssetRequest.js
Expand Up @@ -13,6 +13,7 @@ import type {ConfigAndCachePath} from './ParcelConfigRequest';
import type {TransformationResult} from '../Transformation';

import nullthrows from 'nullthrows';
import ThrowableDiagnostic from '@parcel/diagnostic';
import {hashString} from '@parcel/hash';
import createParcelConfigRequest from './ParcelConfigRequest';
import {runDevDepRequest} from './DevDepRequest';
Expand Down Expand Up @@ -175,7 +176,7 @@ async function run({input, api, farm, invalidateReason, options}: RunInput) {
}

if (error != null) {
throw error;
throw new ThrowableDiagnostic({diagnostic: error});
} else {
return nullthrows(assets);
}
Expand Down

0 comments on commit d9a55b7

Please sign in to comment.