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

Provide informative error message for policy path #1495

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

annakhm
Copy link
Collaborator

@annakhm annakhm commented Dec 31, 2024

Whenever bad path is provided for import, we need to communicate what the expected format is.

@annakhm annakhm changed the title Provide informative import error message for path Provide informative error message for policy path Dec 31, 2024
nsxt/policy_utils.go Outdated Show resolved Hide resolved
nsxt/policy_utils.go Outdated Show resolved Hide resolved
}
if errors.Is(err, ErrNotAPolicyPath) {
if !isValidResourceID(d.Id()) {
return rd, fmt.Errorf("Invalid policy path or id %s; expected path format: %s", d.Id(), pathExample)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this error message makes sense in the case we fail to validate the resource id? The user did not specify a path.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is little sense to give an example of id.. but I rephrased it to avoid confusion, does it look better now?

nsxt/policy_utils.go Show resolved Hide resolved
nsxt/resource_nsxt_policy_dhcp_relay.go Outdated Show resolved Hide resolved
@annakhm annakhm force-pushed the improve-import-error branch from 09e4786 to 95c6ee9 Compare January 3, 2025 22:30
@@ -82,7 +82,7 @@ func resourceNsxtVpcStaticRoutes() *schema.Resource {
Update: resourceNsxtVpcStaticRoutesUpdate,
Delete: resourceNsxtVpcStaticRoutesDelete,
Importer: &schema.ResourceImporter{
State: nsxtVPCPathResourceImporter,
State: getVpcPathResourceImporter("/orgs/[org]/projects/[project]/vpcs/[vpc]/static-routes/[route]"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having these long constant strings within the function call is quite terrible.
I wouldn't ask you to change all of those as it's a pain but maybe it's worthwhile to embed these in the metadata struct somehow or use a constant (especially as we plan to generate this as well).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My personal preference is how the code is written today, I would argue its more readable this way, since you don't need to scroll up to see the example. However, I'm fine with rewriting this with a constant. I think we should have same approach for current PR and future generated code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that generated code is not supposed to be readable. It will be good to have constants, but if it takes time to implement that, there are worse thing that a long literal - like 500+ files in the same directory :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@ksamoray
Copy link
Collaborator

ksamoray commented Jan 9, 2025

LGTM, other than the comment above.

Copy link
Member

@salv-orlando salv-orlando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@annakhm
Copy link
Collaborator Author

annakhm commented Jan 17, 2025

/test-all

@ksamoray
Copy link
Collaborator

@annakhm please rebase this so tests can run

@annakhm annakhm force-pushed the improve-import-error branch from 7ed5df5 to 1ac1e3d Compare January 21, 2025 17:20
@annakhm
Copy link
Collaborator Author

annakhm commented Jan 21, 2025

/test-all

Copy link
Collaborator

@ksamoray ksamoray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also remove nsxtPolicyPathResourceImporter as it isn't used anymore?

func resourceNsxtPolicyTransportZone() *schema.Resource {
return &schema.Resource{
Create: resourceNsxtPolicyTransportZoneCreate,
Read: resourceNsxtPolicyTransportZoneRead,
Update: resourceNsxtPolicyTransportZoneUpdate,
Delete: resourceNsxtPolicyTransportZoneDelete,
Importer: &schema.ResourceImporter{
State: resourceNsxtPolicyTransportZoneImporter,
State: getPolicyPathOrIDResourceImporter(transportZonePathSample),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This importer won't work here, need that one which gathers site_id

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, my bad! thanks Kobi

@annakhm annakhm force-pushed the improve-import-error branch 2 times, most recently from 9b68d50 to 5df4530 Compare January 22, 2025 18:38
@annakhm
Copy link
Collaborator Author

annakhm commented Jan 22, 2025

/test-all

Whenever bad path is provided for import, we need to communicate
what the expected format is.

Signed-off-by: Anna Khmelnitsky <[email protected]>
@annakhm annakhm force-pushed the improve-import-error branch from 5df4530 to 1131e90 Compare January 22, 2025 22:26
@annakhm
Copy link
Collaborator Author

annakhm commented Jan 22, 2025

/test-all

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

Successfully merging this pull request may close these issues.

3 participants