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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnhandledPromiseRejectionWarning: Error: ENOENT, No such file or directory 'undefined' 馃攳馃攳馃攳馃攳馃攳馃攳馃攳馃攳 #102

Open
The-Last-Adam opened this issue Sep 10, 2021 · 7 comments

Comments

@The-Last-Adam
Copy link

Im so close! Please review & tell me where im going wrong.
Repo appears updated since last Tutorial video. Looks like its starting to mint, gives it a DNA and then is looking for the image in the wrong directory. How can i correct this? All layers are in folders in the input folder. /input/Backgrounds/super_rare ect.
Thank you


creating NFT 1 of 10

  • rarity: original
  • dna: 05-06-02-02-06-05-05-05-06--09-010
    (node:12892) UnhandledPromiseRejectionWarning: Error: ENOENT, No such file or directory 'undefined'
    at setSource (C:\Users\Morpheus360\generative-art-opensource-main\node_modules\canvas\lib\image.js:91:13)
    at Image.set (C:\Users\Morpheus360\generative-art-opensource-main\node_modules\canvas\lib\image.js:62:9)
    at C:\Users\Morpheus360\generative-art-opensource-main\node_modules\canvas\index.js:34:15
    at new Promise ()
    at loadImage (C:\Users\Morpheus360\generative-art-opensource-main\node_modules\canvas\index.js:23:10)
    at C:\Users\Morpheus360\generative-art-opensource-main\index.js:75:25
    at new Promise ()
    at loadLayerImg (C:\Users\Morpheus360\generative-art-opensource-main\index.js:74:10)
    at C:\Users\Morpheus360\generative-art-opensource-main\index.js:215:27
    at Array.forEach ()
    (Use node --trace-warnings ... to show where the warning was created)
    (node:12892) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
    (node:12892) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    PS C:\Users\Morpheus360\generative-art-opensource-main>
@The-Last-Adam
Copy link
Author

config.js
/**************************************************************

  • UTILITY FUNCTIONS
    • scroll to BEGIN CONFIG to provide the config values
      *************************************************************/
      const fs = require("fs");
      const dir = __dirname;

// adds a rarity to the configuration. This is expected to correspond with a directory containing the rarity for each defined layer
// @param _id - id of the rarity
// @param _from - number in the edition to start this rarity from
// @param _to - number in the edition to generate this rarity to
// @return a rarity object used to dynamically generate the NFTs
const addRarity = (_id, _from, _to) => {
const _rarityWeight = {
value: _id,
from: _from,
to: _to,
layerPercent: {}
};
return _rarityWeight;
};

// get the name without last 4 characters -> slice .png from the name
const cleanName = (_str) => {
let name = _str.slice(0, -4);
return name;
};

// reads the filenames of a given folder and returns it with its name and path
const getElements = (_path, _elementCount) => {
return fs
.readdirSync(_path)
.filter((item) => !/(^|/).[^\/\.]/g.test(item))
.map((i) => {
return {
id: _elementCount,
name: cleanName(i),
path: ${_path}/${i}
};
});
};

// adds a layer to the configuration. The layer will hold information on all the defined parts and
// where they should be rendered in the image
// @param _id - id of the layer
// @param _position - on which x/y value to render this part
// @param _size - of the image
// @return a layer object used to dynamically generate the NFTs
const addLayer = (_id, _position, _size) => {
if (!_id) {
console.log('error adding layer, parameters id required');
return null;
}
if (!_position) {
_position = { x: 0, y: 0 };
}
if (!_size) {
_size = { width: width, height: height }
}
// add two different dimension for elements:
// - all elements with their path information
// - only the ids mapped to their rarity
let elements = [];
let elementCount = 0;
let elementIdsForRarity = {};
rarityWeights.forEach((rarityWeight) => {
let elementsForRarity = getElements(${dir}/${_id}/${rarityWeight.value});

elementIdsForRarity[rarityWeight.value] = [];
elementsForRarity.forEach((_elementForRarity) => {
  _elementForRarity.id = `${editionDnaPrefix}${elementCount}`;
  elements.push(_elementForRarity);
  elementIdsForRarity[rarityWeight.value].push(_elementForRarity.id);
  elementCount++;
})
elements[rarityWeight.value] = elementsForRarity;

});

let elementsForLayer = {
id: _id,
position: _position,
size: _size,
elements,
elementIdsForRarity
};
return elementsForLayer;
};

// adds layer-specific percentages to use one vs another rarity
// @param _rarityId - the id of the rarity to specifiy
// @param _layerId - the id of the layer to specifiy
// @param _percentages - an object defining the rarities and the percentage with which a given rarity for this layer should be used
const addRarityPercentForLayer = (_rarityId, _layerId, _percentages) => {
let _rarityFound = false;
rarityWeights.forEach((_rarityWeight) => {
if (_rarityWeight.value === _rarityId) {
let _percentArray = [];
for (let percentType in _percentages) {
_percentArray.push({
id: percentType,
percent: _percentages[percentType]
})
}
_rarityWeight.layerPercent[_layerId] = _percentArray;
_rarityFound = true;
}
});
if (!_rarityFound) {
console.log(rarity ${_rarityId} not found, failed to add percentage information);
}
}

/**************************************************************

  • BEGIN CONFIG
    *************************************************************/

// image width in pixels
const width = 1000;
// image height in pixels
const height = 1000;
// description for NFT in metadata file
const description = "Viral Viruses by CRISPR";
// base url to use in metadata file
// the id of the nft will be added to this url, in the example e.g. https://hashlips/nft/1 for NFT with id 1
const baseImageUri = "https://crispr/viral_viruses";
// id for edition to start from
const startEditionFrom = 1;
// amount of NFTs to generate in edition
const editionSize = 10;
// prefix to add to edition dna ids (to distinguish dna counts from different generation processes for the same collection)
const editionDnaPrefix = 0

// create required weights
// for each weight, call 'addRarity' with the id and from which to which element this rarity should be applied
let rarityWeights = [
addRarity('super_rare', 1, 1),
addRarity('rare', 2, 5),
addRarity('original', 5, 10)
];

// create required layers
// for each layer, call 'addLayer' with the id and optionally the positioning and size
// the id would be the name of the folder in your input directory, e.g. 'ball' for ./input/ball
const layers = [
addLayer('Background', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Mouths', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Teeth', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Eye Square Fix', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Eyes', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Body', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Horns', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Horns Shading', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Body Shading', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Mouth Accessories', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Head Accessories', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Eye Accessories', { x: 0, y: 0 }, { width: width, height: height }),
];

// provide any specific percentages that are required for a given layer and rarity level
// all provided options are used based on their percentage values to decide which layer to select from
addRarityPercentForLayer('super_rare', 'Mouth Accessories', { 'super_rare': 10, 'rare': 30, 'original': 60 });
addRarityPercentForLayer('original', 'Background', { 'super_rare': 10, 'rare': 30, 'original': 60 });

module.exports = {
layers,
width,
height,
description,
baseImageUri,
editionSize,
startEditionFrom,
rarityWeights,
};

@The-Last-Adam
Copy link
Author

index.js
/**************************************************************

  • UTILITY FUNCTIONS
    • scroll to BEGIN CONFIG to provide the config values
      *************************************************************/
      const fs = require("fs");
      const dir = __dirname;

// adds a rarity to the configuration. This is expected to correspond with a directory containing the rarity for each defined layer
// @param _id - id of the rarity
// @param _from - number in the edition to start this rarity from
// @param _to - number in the edition to generate this rarity to
// @return a rarity object used to dynamically generate the NFTs
const addRarity = (_id, _from, _to) => {
const _rarityWeight = {
value: _id,
from: _from,
to: _to,
layerPercent: {}
};
return _rarityWeight;
};

// get the name without last 4 characters -> slice .png from the name
const cleanName = (_str) => {
let name = _str.slice(0, -4);
return name;
};

// reads the filenames of a given folder and returns it with its name and path
const getElements = (_path, _elementCount) => {
return fs
.readdirSync(_path)
.filter((item) => !/(^|/).[^\/\.]/g.test(item))
.map((i) => {
return {
id: _elementCount,
name: cleanName(i),
path: ${_path}/${i}
};
});
};

// adds a layer to the configuration. The layer will hold information on all the defined parts and
// where they should be rendered in the image
// @param _id - id of the layer
// @param _position - on which x/y value to render this part
// @param _size - of the image
// @return a layer object used to dynamically generate the NFTs
const addLayer = (_id, _position, _size) => {
if (!_id) {
console.log('error adding layer, parameters id required');
return null;
}
if (!_position) {
_position = { x: 0, y: 0 };
}
if (!_size) {
_size = { width: width, height: height }
}
// add two different dimension for elements:
// - all elements with their path information
// - only the ids mapped to their rarity
let elements = [];
let elementCount = 0;
let elementIdsForRarity = {};
rarityWeights.forEach((rarityWeight) => {
let elementsForRarity = getElements(${dir}/${_id}/${rarityWeight.value});

elementIdsForRarity[rarityWeight.value] = [];
elementsForRarity.forEach((_elementForRarity) => {
  _elementForRarity.id = `${editionDnaPrefix}${elementCount}`;
  elements.push(_elementForRarity);
  elementIdsForRarity[rarityWeight.value].push(_elementForRarity.id);
  elementCount++;
})
elements[rarityWeight.value] = elementsForRarity;

});

let elementsForLayer = {
id: _id,
position: _position,
size: _size,
elements,
elementIdsForRarity
};
return elementsForLayer;
};

// adds layer-specific percentages to use one vs another rarity
// @param _rarityId - the id of the rarity to specifiy
// @param _layerId - the id of the layer to specifiy
// @param _percentages - an object defining the rarities and the percentage with which a given rarity for this layer should be used
const addRarityPercentForLayer = (_rarityId, _layerId, _percentages) => {
let _rarityFound = false;
rarityWeights.forEach((_rarityWeight) => {
if (_rarityWeight.value === _rarityId) {
let _percentArray = [];
for (let percentType in _percentages) {
_percentArray.push({
id: percentType,
percent: _percentages[percentType]
})
}
_rarityWeight.layerPercent[_layerId] = _percentArray;
_rarityFound = true;
}
});
if (!_rarityFound) {
console.log(rarity ${_rarityId} not found, failed to add percentage information);
}
}

/**************************************************************

  • BEGIN CONFIG
    *************************************************************/

// image width in pixels
const width = 1000;
// image height in pixels
const height = 1000;
// description for NFT in metadata file
const description = "Viral Viruses by CRISPR";
// base url to use in metadata file
// the id of the nft will be added to this url, in the example e.g. https://hashlips/nft/1 for NFT with id 1
const baseImageUri = "https://crispr/viral_viruses";
// id for edition to start from
const startEditionFrom = 1;
// amount of NFTs to generate in edition
const editionSize = 10;
// prefix to add to edition dna ids (to distinguish dna counts from different generation processes for the same collection)
const editionDnaPrefix = 0

// create required weights
// for each weight, call 'addRarity' with the id and from which to which element this rarity should be applied
let rarityWeights = [
addRarity('super_rare', 1, 1),
addRarity('rare', 2, 5),
addRarity('original', 5, 10)
];

// create required layers
// for each layer, call 'addLayer' with the id and optionally the positioning and size
// the id would be the name of the folder in your input directory, e.g. 'ball' for ./input/ball
const layers = [
addLayer('Background', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Mouths', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Teeth', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Eye Square Fix', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Eyes', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Body', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Horns', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Horns Shading', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Body Shading', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Mouth Accessories', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Head Accessories', { x: 0, y: 0 }, { width: width, height: height }),
addLayer('Eye Accessories', { x: 0, y: 0 }, { width: width, height: height }),
];

// provide any specific percentages that are required for a given layer and rarity level
// all provided options are used based on their percentage values to decide which layer to select from
addRarityPercentForLayer('super_rare', 'Mouth Accessories', { 'super_rare': 10, 'rare': 30, 'original': 60 });
addRarityPercentForLayer('original', 'Background', { 'super_rare': 10, 'rare': 30, 'original': 60 });

module.exports = {
layers,
width,
height,
description,
baseImageUri,
editionSize,
startEditionFrom,
rarityWeights,
};

@lordexe
Copy link

lordexe commented Sep 10, 2021

same issue

@The-Last-Adam The-Last-Adam changed the title UnhandledPromiseRejectionWarning: Error: ENOENT, No such file or directory 'undefined' UnhandledPromiseRejectionWarning: Error: ENOENT, No such file or directory 'undefined' <<<---------------------------------------------------------- Sep 11, 2021
@The-Last-Adam
Copy link
Author

I have ran npm install canvas and still same error.

Is this possibly a rarity config issue? Do i need to add super_rare, rare, & original to every single layer. I have 12 so would the total be 36 lines of code. 3 rarity types for all 12 layers?

@The-Last-Adam
Copy link
Author

Also I've went through all of the closed tickets and applied everything I learned and still same error. Please advise.

@The-Last-Adam
Copy link
Author

Do i need to rename the actual image layer file name to something specific?

@The-Last-Adam The-Last-Adam changed the title UnhandledPromiseRejectionWarning: Error: ENOENT, No such file or directory 'undefined' <<<---------------------------------------------------------- UnhandledPromiseRejectionWarning: Error: ENOENT, No such file or directory 'undefined' 馃攳馃攳馃攳馃攳馃攳馃攳馃攳馃攳 Sep 13, 2021
@aleworkout
Copy link

Try putting layer files name like this

layer1_folder > layer1.png
layer2_folder > layer
2.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants