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

fix(gatsby-plugin-image): Better error logging (#28741) #28855

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions packages/gatsby-plugin-image/src/node-apis/image-processing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
Node,
GatsbyCache,
Reporter,
ParentSpanPluginArgs,
Expand All @@ -12,7 +11,7 @@ import fs from "fs-extra"
import path from "path"
import { ImageProps, SharpProps } from "../utils"
import { watchImage } from "./watcher"
import { createRemoteFileNode } from "gatsby-source-filesystem"
import { createRemoteFileNode, FileSystemNode } from "gatsby-source-filesystem"

const supportedTypes = new Set([`image/png`, `image/jpeg`, `image/webp`])
export interface IImageMetadata {
Expand All @@ -30,11 +29,11 @@ export async function createImageNode({
fullPath: string
createNodeId: ParentSpanPluginArgs["createNodeId"]
createNode: Actions["createNode"]
}): Promise<Node | undefined> {
}): Promise<FileSystemNode | undefined> {
if (!fs.existsSync(fullPath)) {
return undefined
}
const file: Node = await createFileNode(fullPath, createNodeId, {})
const file: FileSystemNode = await createFileNode(fullPath, createNodeId, {})

if (!file) {
return undefined
Expand Down Expand Up @@ -73,7 +72,7 @@ export async function writeImages({
}): Promise<void> {
const promises = [...images.entries()].map(
async ([hash, { src, ...args }]) => {
let file: Node | undefined
let file: FileSystemNode | undefined
let fullPath
if (process.env.GATSBY_EXPERIMENTAL_REMOTE_IMAGES && isRemoteURL(src)) {
try {
Expand Down Expand Up @@ -155,7 +154,7 @@ export async function writeImages({
}

export async function writeImage(
file: Node,
file: FileSystemNode,
args: SharpProps,
pathPrefix: string,
reporter: Reporter,
Expand All @@ -176,9 +175,9 @@ export async function writeImage(
// Write the image properties to the cache
await fs.writeJSON(filename, sharpData)
} else {
reporter.warn(`Could not process image`)
reporter.warn(`Could not process image ${file.relativePath}`)
}
} catch (e) {
reporter.warn(`Error processing image`)
reporter.warn(`Error processing image ${file.relativePath}. \n${e.message}`)
}
}
11 changes: 3 additions & 8 deletions packages/gatsby-plugin-image/src/node-apis/watcher.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import chokidar, { FSWatcher } from "chokidar"
import {
Actions,
ParentSpanPluginArgs,
GatsbyCache,
Reporter,
Node,
} from "gatsby"
import { Actions, ParentSpanPluginArgs, GatsbyCache, Reporter } from "gatsby"
import { createImageNode, IImageMetadata, writeImage } from "./image-processing"
import { FileSystemNode } from "gatsby-source-filesystem"

let watcher: FSWatcher | undefined

Expand Down Expand Up @@ -62,7 +57,7 @@ async function updateImages({
reporter,
}: {
cache: GatsbyCache
node: Node
node: FileSystemNode
pathPrefix: string
reporter: Reporter
}): Promise<void> {
Expand Down