Skip to content

Commit f45ba68

Browse files
GatsbyJS Botascorbic
andauthored
fix(gatsby-plugin-image): Better error logging (#28741) (#28855)
(cherry picked from commit 305fa64) Co-authored-by: Matt Kane <[email protected]>
1 parent f19c807 commit f45ba68

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

packages/gatsby-plugin-image/src/node-apis/image-processing.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
Node,
32
GatsbyCache,
43
Reporter,
54
ParentSpanPluginArgs,
@@ -12,7 +11,7 @@ import fs from "fs-extra"
1211
import path from "path"
1312
import { ImageProps, SharpProps } from "../utils"
1413
import { watchImage } from "./watcher"
15-
import { createRemoteFileNode } from "gatsby-source-filesystem"
14+
import { createRemoteFileNode, FileSystemNode } from "gatsby-source-filesystem"
1615

1716
const supportedTypes = new Set([`image/png`, `image/jpeg`, `image/webp`])
1817
export interface IImageMetadata {
@@ -30,11 +29,11 @@ export async function createImageNode({
3029
fullPath: string
3130
createNodeId: ParentSpanPluginArgs["createNodeId"]
3231
createNode: Actions["createNode"]
33-
}): Promise<Node | undefined> {
32+
}): Promise<FileSystemNode | undefined> {
3433
if (!fs.existsSync(fullPath)) {
3534
return undefined
3635
}
37-
const file: Node = await createFileNode(fullPath, createNodeId, {})
36+
const file: FileSystemNode = await createFileNode(fullPath, createNodeId, {})
3837

3938
if (!file) {
4039
return undefined
@@ -73,7 +72,7 @@ export async function writeImages({
7372
}): Promise<void> {
7473
const promises = [...images.entries()].map(
7574
async ([hash, { src, ...args }]) => {
76-
let file: Node | undefined
75+
let file: FileSystemNode | undefined
7776
let fullPath
7877
if (process.env.GATSBY_EXPERIMENTAL_REMOTE_IMAGES && isRemoteURL(src)) {
7978
try {
@@ -155,7 +154,7 @@ export async function writeImages({
155154
}
156155

157156
export async function writeImage(
158-
file: Node,
157+
file: FileSystemNode,
159158
args: SharpProps,
160159
pathPrefix: string,
161160
reporter: Reporter,
@@ -176,9 +175,9 @@ export async function writeImage(
176175
// Write the image properties to the cache
177176
await fs.writeJSON(filename, sharpData)
178177
} else {
179-
reporter.warn(`Could not process image`)
178+
reporter.warn(`Could not process image ${file.relativePath}`)
180179
}
181180
} catch (e) {
182-
reporter.warn(`Error processing image`)
181+
reporter.warn(`Error processing image ${file.relativePath}. \n${e.message}`)
183182
}
184183
}

packages/gatsby-plugin-image/src/node-apis/watcher.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import chokidar, { FSWatcher } from "chokidar"
2-
import {
3-
Actions,
4-
ParentSpanPluginArgs,
5-
GatsbyCache,
6-
Reporter,
7-
Node,
8-
} from "gatsby"
2+
import { Actions, ParentSpanPluginArgs, GatsbyCache, Reporter } from "gatsby"
93
import { createImageNode, IImageMetadata, writeImage } from "./image-processing"
4+
import { FileSystemNode } from "gatsby-source-filesystem"
105

116
let watcher: FSWatcher | undefined
127

@@ -62,7 +57,7 @@ async function updateImages({
6257
reporter,
6358
}: {
6459
cache: GatsbyCache
65-
node: Node
60+
node: FileSystemNode
6661
pathPrefix: string
6762
reporter: Reporter
6863
}): Promise<void> {

0 commit comments

Comments
 (0)