private void WriteReasonError(System.Management.Automation.Job job) { PSRemotingChildJob job2 = job as PSRemotingChildJob; if ((job2 != null) && (job2.FailureErrorRecord != null)) { this._results.Add(new PSStreamObject(PSStreamObjectType.Error, job2.FailureErrorRecord, job2.InstanceId)); } else if (job.JobStateInfo.Reason != null) { Exception reason = job.JobStateInfo.Reason; Exception exception = reason; JobFailedException exception3 = reason as JobFailedException; if (exception3 != null) { exception = exception3.Reason; } ErrorRecord record = new ErrorRecord(exception, "JobStateFailed", ErrorCategory.InvalidResult, null); if ((exception3 != null) && (exception3.DisplayScriptPosition != null)) { if (record.InvocationInfo == null) { record.SetInvocationInfo(new InvocationInfo(null, null)); } record.InvocationInfo.DisplayScriptPosition = exception3.DisplayScriptPosition; } this._results.Add(new PSStreamObject(PSStreamObjectType.Error, record, job.InstanceId)); } }
/// <summary> /// Sets job status to <see cref="FailedState"/>. /// Creates new <see cref="JobFailedException"/> with <paramref name="error"/> message. /// </summary> /// <param name="context">Job context.</param> /// <param name="error">Error message for failed state.</param> private static void SetFailedState(ElectStateContext context, string error) { var jobFailedException = new JobFailedException(error); context.CandidateState = new FailedState(jobFailedException); }