nautobot / nautobot-app-welcome-wizard

Magic and wonder UI wizard that simplifies getting started with Nautobot.
https://docs.nautobot.com/projects/welcome-wizard/en/latest/
Other
13 stars 7 forks source link

Add error output to DeviceType import #97

Open joewesch opened 10 months ago

joewesch commented 10 months ago

Environment

Proposed Functionality

When loading a custom yaml file for a DeviceType, required fields may be missed and the only error that we get is from the form's .save() method. This error message, unfortunately, isn't too helpful:

ValueError: The DeviceType could not be created because the data didn't validate.

We should wrap the save method in a try block and if it fails look for validation errors to present to the user. Here is an example of a possible change to the existing code:

    dtif = DeviceTypeImportForm(data)
    try:
        devtype = dtif.save()
    except ValueError as exc:
        if dtif.errors:
            raise ValueError(f"Unable to import this device_type, {dtif.errors}")
        raise exc

Use Case

whitej6 commented 10 months ago

Thoughts on below?

dtif = DeviceTypeImportForm(data)
if not dtif.is_valid():
    raise ValueError(f"Unable to import this device_type, {dtif.errors}")
dtif.save()

Not verified and not sure if the error you're trying to account for is covered. Also I would have thought it would raise ValidationError instead of ValueError.