Skip to content

Replace "Dbg.Assert" with 'if () throw' in CSVCommands.cs.#6910

Merged
iSazonov merged 3 commits intoPowerShell:masterfrom
sethvs:DbgAssert
Jun 5, 2018
Merged

Replace "Dbg.Assert" with 'if () throw' in CSVCommands.cs.#6910
iSazonov merged 3 commits intoPowerShell:masterfrom
sethvs:DbgAssert

Conversation

@sethvs
Copy link
Copy Markdown
Contributor

@sethvs sethvs commented May 21, 2018

PR Summary

As of discussion in #6816

PR Checklist

@@ -331,6 +331,11 @@ private void CreateFileStream()
{
Dbg.Assert(_path != null, "FileName is mandatory parameter");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we can remove the asserts now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed.


if (_path == null)
{
throw new InvalidOperationException("FileName is mandatory parameter");
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.

Since the strings are now user visible, they need to be moved to a resx file. This applies to all the changes that now throw exceptions.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Shall we localize the strings? In the case we should review all code base.

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.

@iSazonov I don't believe we localize assert strings because they are for debug only usage. Exception strings are handled like any other display string.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@dantraMSFT In this case, I think there is no point in transferring these throw debug strings to the resource files.

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.

@iSazonov: I believe there is. We are effectively creating new strings that are displayed to the user. The fact that they were previously assert strings doesn't change that, IMHO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What about resx?
Should I move strings to CsvCommandStrings.resx?

Copy link
Copy Markdown
Collaborator

@iSazonov iSazonov May 23, 2018

Choose a reason for hiding this comment

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

We just discuss this becouse of never do this previously.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved.

Copy link
Copy Markdown
Contributor

@dantraMSFT dantraMSFT May 23, 2018

Choose a reason for hiding this comment

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

@iSazonov: There already is a guideline in docs\dev-process\coding-guidelines.

Resource strings used for errors or UI should be put in resource files (.resx) so that they can be localized later.

With few, ahem, exceptions, strings passed as the message to an exception are error strings and should be in the resx file. The fact that hit used to be a dbg.assert doesn't change this (IMHO).

As far as the string used in an Assert, I prefer to avoid them, especially when not backed up by code, They are a useful debugging aid though but I would not expect the strings to be localized.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@dantraMSFT Thanks for clarify!

@iSazonov
Copy link
Copy Markdown
Collaborator

iSazonov commented Jun 5, 2018

@dantraMSFT Could you please update your review?

@iSazonov iSazonov changed the title Add "if" statements to places where "Dbg.Assert" is only existing check in CSVCommands.cs. Replace "Dbg.Assert" with 'if () throw' in CSVCommands.cs. Jun 5, 2018
@iSazonov iSazonov self-assigned this Jun 5, 2018
@iSazonov iSazonov merged commit 3b1a4a4 into PowerShell:master Jun 5, 2018
@sethvs sethvs deleted the DbgAssert branch June 7, 2018 09:17
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