question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Using sharp only works the first time, no error msg

See original GitHub issue

I’m trying to generate multiple sizes of an array of image files. However this just works the first image, the next ones will fail. I’m using a static function, so there should be few error potential. The error appears just after the input file changes. All iterations for the first file work properly. Do I need to manually clear some sharp cache after all sizes were generated?

public static async createSizesOfImage(path: string, sizes?: number[]): Promise<number[]> {
    if (!sizes || sizes.length === 0) sizes = [250, 640, 1280, 1600, 2200];
    let error: Error, info: any;

    const generatedSizes: number[] = [];

    for (const size of sizes) {
        const newFilePath = path.replace('.', '_s' + size + '.');
        LoggerService.log('ImageService - createSizesOfImage(): Generating image s' + size);
        console.warn('hi i am here');
        [error, info] = await to(
            sharp(path)
                .resize(size, size, { fit: 'inside', withoutEnlargement: true })
                .toFile(newFilePath)
        );
        if (error) {
            console.error('ImageService - createSizesOfImage(): Failed to generate s' + size + ' of ' + path, error);
            throw new Error();
        }

        generatedSizes.push(size);
    }

    return generatedSizes;
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lovellcommented, Dec 28, 2018

Closing due to inactivity but please feel free to re-open with a standalone code sample if more help is required.

0reactions
lovellcommented, Nov 21, 2018

This should all work and I can’t see anything obviously wrong with the code presented here so far. Are you able to provide a standalone code sample, removing some of the other dependencies such as to? Which version/platform is this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to find the reason for a failed Build without any error or ...
I noticed that if "Build + Intellisense" is selected in the Error List, it causes the error messages to be swallowed. Change this...
Read more >
Fix program errors and improve code - Visual Studio ...
This article describes some basic ways Visual Studio can help you find and fix problems in your code, including build errors, code analysis, ......
Read more >
Bug #306401 “Brother MFC8840D errors on 1st print job”
Printing the 1st time to printer after printer power-up errors. The second and all subsequent attempts to print succeed with no errors.
Read more >
Common .NET Software Errors and How to Fix Them
We've aggregated the 50 top .NET software errors. It includes exceptions, broken data bindings, memory leaks, etc. Find solutions on ways to ...
Read more >
Bug listing with status RESOLVED with resolution FIXED as at ...
Bug listing with status RESOLVED with resolution FIXED as at 2022/12/24 19:46:07 ... Bug:120 - "kvm not working after new ebuild's of kde"...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found