This repository was archived by the owner on Oct 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Fix 'Cannot read properties of undefined (reading 'map')' error in deploy command #58
Open
dmvt
wants to merge
1
commit into
Phala-Network:main
Choose a base branch
from
dmvt:fix-envs-map-undefined-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -280,15 +280,17 @@ const validateNodeandKmsandImage = async (options: Options, client: Client) => { | |
| throw new Error(`Validation error: ${nodes_result.error.issues}`) | ||
| } | ||
| } | ||
| const nodes = nodes_result.data as any; | ||
| const nodesData = nodes_result.data as any; | ||
| // Handle both possible data structures | ||
| const nodes = nodesData.nodes || nodesData; | ||
| let target = null; | ||
| let kms = null; | ||
| let privateKey = options.privateKey; | ||
| // If specified node, find it | ||
| if (options.nodeId) { | ||
| target = nodes.nodes.find((node) => node.teepod_id === Number(options.nodeId)); | ||
| target = nodes.find((node) => node.teepod_id === Number(options.nodeId)); | ||
| if (!target) { | ||
| throw new Error(`Node ${options.nodeId} not found, available nodes: ${nodes.nodes.map(t => t.teepod_id).join(', ')}`); | ||
| throw new Error(`Node ${options.nodeId} not found, available nodes: ${nodes.map(t => t.teepod_id).join(', ')}`); | ||
| } | ||
| } else { | ||
| // If interactive, let user select a node | ||
|
|
@@ -297,19 +299,19 @@ const validateNodeandKmsandImage = async (options: Options, client: Client) => { | |
| type: 'list', | ||
| name: 'node', | ||
| message: 'Select a Node to use:', | ||
| choices: nodes.nodes.map(t => ({ | ||
| choices: nodes.map(t => ({ | ||
| name: `${t.name} (Region: ${t.region_identifier})`, | ||
| value: t | ||
| })) | ||
| }]); | ||
| target = node; | ||
| } else { | ||
| // If no specified node, use the first one. | ||
| target = nodes.nodes[0]; | ||
| target = nodes[0]; | ||
| } | ||
| } | ||
| if (!target) { | ||
| throw new Error(`No available nodes found, available nodes: ${nodes.nodes.map(t => t.teepod_id).join(', ')}`); | ||
| throw new Error(`No available nodes found, available nodes: ${nodes.map(t => t.teepod_id).join(', ')}`); | ||
| } | ||
| // If the target node supports on-chain kms, check if kms is specified | ||
| if (target.support_onchain_kms) { | ||
|
|
@@ -321,15 +323,17 @@ const validateNodeandKmsandImage = async (options: Options, client: Client) => { | |
| throw new Error(`Validation error: ${kms_result.error.issues}`) | ||
| } | ||
| } | ||
| const kms_list = kms_result.data as any; | ||
| const kmsData = kms_result.data as any; | ||
| // Handle both possible data structures | ||
| const kms_list = kmsData.items || kmsData; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's not a safe operation. |
||
| if (!options.kmsId) { | ||
| if (options.interactive) { | ||
| const { kmsChoice } = await inquirer.prompt([ | ||
| { | ||
| type: 'list', | ||
| name: 'kmsChoice', | ||
| message: 'Select a KMS to use:', | ||
| choices: kms_list.items.map(t => ({ | ||
| choices: kms_list.map(t => ({ | ||
| name: t.chain_id ? | ||
| `${t.slug} (Chain ID: ${t.chain_id})` : | ||
| `${t.slug} (No chain required)`, | ||
|
|
@@ -339,25 +343,25 @@ const validateNodeandKmsandImage = async (options: Options, client: Client) => { | |
| ]); | ||
| kms = kmsChoice; | ||
| } else { | ||
| throw new Error(`Node ${target.name} requires a KMS ID for Contract Owned CVM, available kms: ${kms_list.items.map(t => t.slug).join(', ')}`); | ||
| throw new Error(`Node ${target.name} requires a KMS ID for Contract Owned CVM, available kms: ${kms_list.map(t => t.slug).join(', ')}`); | ||
| } | ||
| } else { | ||
| // Find the specified kms | ||
| kms = kms_list.items.find((kms) => kms.slug === options.kmsId || kms.id === options.kmsId); | ||
| kms = kms_list.find((kms) => kms.slug === options.kmsId || kms.id === options.kmsId); | ||
| } | ||
| if (!kms) { | ||
| throw new Error(`KMS ${options.kmsId} not found, available kms: ${kms_list.items.map(t => t.slug).join(', ')}`); | ||
| throw new Error(`KMS ${options.kmsId} not found, available kms: ${kms_list.map(t => t.slug).join(', ')}`); | ||
| } else { | ||
| privateKey = await validatePrivateKey({ ...options, kmsId: kms.id }, kms.chain_id); | ||
| } | ||
| } | ||
|
|
||
| // Default image is the first one | ||
| let image = target.images[0]; | ||
| let image = target.images && target.images[0]; | ||
| if (options.image) { | ||
| image = target.images.find((image) => image.name === options.image); | ||
| image = target.images && target.images.find((image) => image.name === options.image); | ||
| if (!image) { | ||
| throw new Error(`Image ${options.image} not found in the node ${target.name}, available images: ${target.images.map(t => t.name).join(', ')}.`); | ||
| throw new Error(`Image ${options.image} not found in the node ${target.name}, available images: ${target.images ? target.images.map(t => t.name).join(', ') : 'NO IMAGES'}.`); | ||
| } | ||
| } else { | ||
| if (options.interactive) { | ||
|
|
@@ -366,17 +370,17 @@ const validateNodeandKmsandImage = async (options: Options, client: Client) => { | |
| type: 'list', | ||
| name: 'imageChoice', | ||
| message: 'Select an image to use:', | ||
| choices: target.images.map(t => ({ | ||
| choices: target.images ? target.images.map(t => ({ | ||
| name: `${t.name}`, | ||
| value: t | ||
| })) | ||
| })) : [] | ||
| } | ||
| ]); | ||
| image = imageChoice; | ||
| } | ||
| } | ||
| if (!image) { | ||
| throw new Error(`No available OS images found in the node ${target.name}, available images: ${target.images.map(t => t.name).join(', ')}.`); | ||
| throw new Error(`No available OS images found in the node ${target.name}, available images: ${target.images ? target.images.map(t => t.name).join(', ') : 'NO IMAGES'}.`); | ||
| } | ||
|
|
||
| return { | ||
|
|
@@ -398,7 +402,7 @@ const deployNewCvm = async (validatedOptions: Options, docker_compose_yml: strin | |
| name: name, | ||
| compose_file: { | ||
| docker_compose_file: docker_compose_yml, | ||
| allowed_envs: envs.map((env) => env.key), | ||
| allowed_envs: envs ? envs.map((env) => env.key) : [], | ||
| }, | ||
| vcpu: vcpu, | ||
| memory: memoryMB, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's not a safe operation.