Skip to content

Replace empty catch blocks with explicit checks and fix the ExportImpot namespace - #988

Merged
KrzysztofPajak merged 3 commits into
developfrom
refactor/n17-empty-catches
Oct 24, 2026
Merged

KrzysztofPajak merged 3 commits into
developfrom
refactor/n17-empty-catches

Conversation

@KrzysztofPajak

@KrzysztofPajak KrzysztofPajak commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Part of the architecture backlog (item N17: leftover catch { }, ExportImpot typo)
Type: refactor

Issue

Seven places swallowed every exception with an empty catch, mostly to turn an invalid date into null. That hides real failures, and in the plugin upload it hid a failed delete of the previous plugin folder, which then surfaced later as a less clear extraction error. The order export schema also lived in a misspelled namespace, Grand.Business.Checkout.Services.ExportImpot.

Solution

  • RegisterModel.ParseDateOfBirth, CustomerInfoModel.ParseDateOfBirth, BlogPagingFilteringModel.GetParsedMonth and the date field in ContactAttributeParser.GetParseContactAttributes check year, month and day range (DateTime.DaysInMonth) instead of catching the DateTime constructor exception. Invalid or missing input still gives null / no attribute.
  • PluginController.Upload no longer deletes the previous plugin folder in place. It moves it into the temp upload folder, extracts the new version, and moves the previous one back if extraction fails. On Windows a folder with an assembly the process has loaded can be moved but not deleted, so a temp folder that cannot be deleted after a finished upload is logged as a warning and removed by the next upload (the plugin loader only reads folders directly under Plugins, so the copy there is never loaded). UploadPlugin now catches upload failures and shows them through Error(exc) with a redirect to the list, instead of a 500.
  • ContactAttributeChangeCommandHandler parses the date field the same way as ContactAttributeParser.
  • SystemController.SystemInfo sets OperatingSystem and AspNetInfo directly; RuntimeInformation.OSDescription does not throw, and AspNetInfo now shows RuntimeInformation.FrameworkDescription (RuntimeEnvironment.GetSystemVersion() returned v4.0.30319 on modern .NET).
  • Services/ExportImpot → Services/ExportImport (namespace Grand.Business.Checkout.Services.ExportImport).

Breaking changes

  • Code outside this repository that imports Grand.Business.Checkout.Services.ExportImpot must change the using. OrderSchemaProperty is only registered in DI; no plugin or module in this repository references it.
  • No route, setting, permission, localization key or persisted value changes.

Testing

  1. dotnet build src/Web/Grand.Web.Admin: succeeds.
  2. New Grand.Web.Tests/Models/DateParsingModelsTests (date of birth: leap day, 29 Feb in a non-leap year, month 13, 31 April, year 0, missing parts; blog month: valid, out of range, non-numeric, wrong shape, empty) and a data-driven date field test in ContactAttributeParserTests (leap day, 31 April, day 0, month 0/13, year 0/1/9999/10000, non-numeric, missing year). They describe the previous behavior and pass before and after.
  3. dotnet test: ContactAttributeParserTests 23/23, Grand.Web.Tests filtered to the new tests and the customer validators 23/23, OrderSchemaPropertyTests 1/1.

…ot namespace

- Date of birth, blog archive month and the contact form date field validate
  year, month and day instead of swallowing the DateTime constructor exception.
- Plugin upload deletes the previous plugin folder only when it exists and no
  longer hides a failed delete.
- System info reads the OS description and runtime version directly; neither
  call throws.
- Grand.Business.Checkout.Services.ExportImpot is renamed to ExportImport.
Copilot AI balanced review requested due to automatic review settings October 24, 2026 06:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

…ion when it fails

- UploadPlugin catches the exception and shows it through Error(exc) instead of returning a 500
- the previous plugin folder is moved into the temp upload folder rather than deleted in place, and moved back if extraction fails
- ContactAttributeChangeCommandHandler parses the date field the same way as ContactAttributeParser
- System info shows RuntimeInformation.FrameworkDescription
- more date edge cases in the contact attribute parser test
Comment on lines +287 to +291
catch (Exception exc)
{
Error(exc);
return RedirectToAction("List");
}
ZipFile.ExtractToDirectory(archivePath, pluginsPath);
//move the previous version into the temp upload folder instead of deleting it in place:
//a locked assembly fails the move before anything is changed, and a failed extraction puts it back
var previousVersionPath = Path.Combine(Path.GetDirectoryName(archivePath)!, Guid.NewGuid().ToString());
@KrzysztofPajak
KrzysztofPajak merged commit 89bae1a into develop Oct 24, 2026
9 checks passed
@KrzysztofPajak
KrzysztofPajak deleted the refactor/n17-empty-catches branch October 24, 2026 08:29
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.

2 participants