Skip to content

Commit 698576f

Browse files
committed
Replaced error writing to new logging framework
1 parent 193a5aa commit 698576f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+66
-71
lines changed

src/Commands/Admin/AddTenantTheme.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected override void ExecuteCmdlet()
4141
}
4242
else
4343
{
44-
WriteError(new ErrorRecord(new Exception($"Theme exists"), "THEMEEXISTS", ErrorCategory.ResourceExists, Identity.Name));
44+
LogError("Theme exists");
4545
}
4646
}
4747
else

src/Commands/Admin/NewSite.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ protected override void ExecuteCmdlet()
190190
}
191191
catch (Exception ex)
192192
{
193-
WriteError(ex);
193+
LogError(ex);
194194
}
195195
}
196196
else
197197
{
198-
WriteError(new PSInvalidOperationException("Creating a new teamsite requires an underlying Microsoft 365 group. In order to create this we need to acquire an access token for the Microsoft Graph. This is not possible using ACS App Only connections."));
198+
LogError(new PSInvalidOperationException("Creating a new teamsite requires an underlying Microsoft 365 group. In order to create this we need to acquire an access token for the Microsoft Graph. This is not possible using ACS App Only connections."));
199199
}
200200
}
201201
else

src/Commands/AzureAD/GetAzureADAppPermission.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected override void ExecuteCmdlet()
2323
var app = Identity.GetApp(GraphRequestHelper);
2424
if (app == null)
2525
{
26-
WriteError(new PSArgumentException("Azure AD App not found"));
26+
LogError(new PSArgumentException("Azure AD App not found"));
2727
}
2828
WriteObject(ConvertToPSObject(app));
2929
}

src/Commands/AzureAD/SetAzureADGroup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ protected override void ExecuteCmdlet()
9898
catch (Exception e)
9999
{
100100
while (e.InnerException != null) e = e.InnerException;
101-
WriteError(new ErrorRecord(e, "GROUPUPDATEFAILED", ErrorCategory.InvalidOperation, this));
101+
LogError(e);
102102
}
103103
}
104104
else
105105
{
106-
WriteError(new ErrorRecord(new Exception("Group not found"), "GROUPNOTFOUND", ErrorCategory.ObjectNotFound, this));
106+
LogError("Group not found");
107107
}
108108
}
109109
}

src/Commands/Base/BasePSCmdlet.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,16 @@ public bool ParameterSpecified(string parameterName)
130130
/// Allows logging an error
131131
/// </summary>
132132
/// <param name="exception">The exception to log as an error</param>
133-
internal void WriteError(Exception exception)
133+
internal void LogError(Exception exception)
134134
{
135-
WriteError(exception.Message);
135+
LogError(exception.Message);
136136
}
137137

138138
/// <summary>
139139
/// Allows logging an error
140140
/// </summary>
141141
/// <param name="message">The message to log</param>
142-
internal void WriteError(string message)
142+
internal void LogError(string message)
143143
{
144144
Utilities.Logging.LoggingUtility.Error(this, message, correlationId: CorrelationId);
145145
}

src/Commands/Base/GetAccessToken.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected override void ExecuteCmdlet()
8484

8585
if (accessTokenValue == null)
8686
{
87-
WriteError(new PSArgumentException("Unable to retrieve access token"));
87+
LogError(new PSArgumentException("Unable to retrieve access token"));
8888
}
8989
if (ListPermissionScopes.IsPresent)
9090
{

src/Commands/Base/GetManagedAppId.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protected override void ProcessRecord()
2020
}
2121
else
2222
{
23-
WriteError(new ErrorRecord(new Exception("AppId not found"), "APPIDNOTFOUND", ErrorCategory.AuthenticationError, this));
23+
LogError("AppId not found");
2424
}
2525
}
2626
}

src/Commands/Base/GetStoredCredential.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected override void ProcessRecord()
1818
}
1919
else
2020
{
21-
WriteError(new ErrorRecord(new System.Exception("Credentials not found"), "CREDSNOTFOUND", ErrorCategory.AuthenticationError, this));
21+
LogError(new System.Exception("Credentials not found"));
2222
}
2323
}
2424
}

src/Commands/Base/PipeBinds/ContentTypePipeBind.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,20 +240,20 @@ internal PnPCore.IContentType GetContentTypeOrThrow(string paramName, PnP.Core.S
240240
=> GetContentType(context, searchInSiteHierarchy)
241241
?? throw new PSArgumentException(NotFoundMessage(searchInSiteHierarchy), paramName);
242242

243-
internal ContentType GetContentTypeOrError(Cmdlet cmdlet, string paramName, Web web, bool searchInSiteHierarchy = true)
243+
internal ContentType GetContentTypeOrError(BasePSCmdlet cmdlet, string paramName, Web web, bool searchInSiteHierarchy = true)
244244
{
245245
var ct = GetContentType(web, searchInSiteHierarchy);
246246
if (ct is null)
247-
cmdlet.WriteError(new ErrorRecord(new PSArgumentException(NotFoundMessage(searchInSiteHierarchy), paramName), "CONTENTTYPEDOESNOTEXIST", ErrorCategory.InvalidArgument, this));
247+
cmdlet.LogError(new PSArgumentException(NotFoundMessage(searchInSiteHierarchy), paramName));
248248
return ct;
249249
}
250250

251-
internal PnPCore.IContentType GetContentTypeOrError(Cmdlet cmdlet, string paramName, PnP.Core.Services.PnPContext context, bool searchInSiteHierarchy = true)
251+
internal PnPCore.IContentType GetContentTypeOrError(BasePSCmdlet cmdlet, string paramName, PnP.Core.Services.PnPContext context, bool searchInSiteHierarchy = true)
252252
{
253253
var ct = GetContentType(context, searchInSiteHierarchy);
254254
if (ct is null)
255255
{
256-
cmdlet.WriteError(new ErrorRecord(new PSArgumentException(NotFoundMessage(searchInSiteHierarchy), paramName), "CONTENTTYPEDOESNOTEXIST", ErrorCategory.InvalidArgument, this));
256+
cmdlet.LogError(new PSArgumentException(NotFoundMessage(searchInSiteHierarchy), paramName));
257257
}
258258
return ct;
259259
}
@@ -262,19 +262,19 @@ internal ContentType GetContentTypeOrThrow(string paramName, List list)
262262
=> GetContentType(list)
263263
?? throw new PSArgumentException(NotFoundMessage(list), paramName);
264264

265-
internal ContentType GetContentTypeOrError(Cmdlet cmdlet, string paramName, List list)
265+
internal ContentType GetContentTypeOrError(BasePSCmdlet cmdlet, string paramName, List list)
266266
{
267267
var ct = GetContentType(list);
268268
if (ct is null)
269-
cmdlet.WriteError(new ErrorRecord(new PSArgumentException(NotFoundMessage(list), paramName), "CONTENTTYPEDOESNOTEXIST", ErrorCategory.InvalidArgument, this));
269+
cmdlet.LogError(new PSArgumentException(NotFoundMessage(list), paramName));
270270
return ct;
271271
}
272272

273-
internal PnPCore.IContentType GetContentTypeOrError(Cmdlet cmdlet, string paramName, PnPCore.IList list)
273+
internal PnPCore.IContentType GetContentTypeOrError(BasePSCmdlet cmdlet, string paramName, PnPCore.IList list)
274274
{
275275
var ct = GetContentType(list);
276276
if (ct is null)
277-
cmdlet.WriteError(new ErrorRecord(new PSArgumentException(NotFoundMessage(list), paramName), "CONTENTTYPEDOESNOTEXIST", ErrorCategory.InvalidArgument, this));
277+
cmdlet.LogError(new PSArgumentException(NotFoundMessage(list), paramName));
278278
return ct;
279279
}
280280

src/Commands/Base/PnPConnectedCmdlet.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,8 @@ protected override void ProcessRecord()
113113
{
114114
ex.Data["CorrelationId"] = Connection.Context.TraceCorrelationId;
115115
ex.Data["TimeStampUtc"] = DateTime.UtcNow;
116-
var errorDetails = new ErrorDetails(errorMessage);
117116

118-
errorDetails.RecommendedAction = "Use Get-PnPException for more details.";
119-
var errorRecord = new ErrorRecord(ex, "EXCEPTION", ErrorCategory.WriteError, null);
120-
errorRecord.ErrorDetails = errorDetails;
121-
122-
WriteError(errorRecord);
117+
LogError(errorMessage);
123118
}
124119

125120
}

0 commit comments

Comments
 (0)