Skip to content

Commit 53c8bae

Browse files
authored
Added code values to errors reported from tasks (#39)
1 parent 5a82142 commit 53c8bae

File tree

3 files changed

+67
-34
lines changed

3 files changed

+67
-34
lines changed

docfx/build-tasks/index.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,23 @@ If not explicitly set this is determined by the automated build flags as describ
218218
section of this document.
219219

220220
## Detected Error Conditions
221-
|Code |Description|
222-
|---------|-----------|
223-
| CSM001 | BuildMajor is a required property, either set it as a global or in the build version XML |
224-
| CSM002 | BuildMinor is a required property, either set it as a global or in the build version XML |
225-
| CSM003 | BuildPatch is a required property, either set it as a global or in the build version XML |
226-
| CSM004 | FileVersion property not provided AND FileVersionMajor property not found to create it from |
227-
| CSM005 | FileVersion property not provided AND FileVersionMinor property not found to create it from |
228-
| CSM006 | FileVersion property not provided AND FileVersionBuild property not found to create it from |
229-
| CSM007 | FileVersion property not provided AND FileVersionRevision property not found to create it from |
221+
|Code |Description|
222+
|--------|-----------|
223+
| CSM001 | BuildMajor is a required property, either set it as a global or in the build version XML |
224+
| CSM002 | BuildMinor is a required property, either set it as a global or in the build version XML |
225+
| CSM003 | BuildPatch is a required property, either set it as a global or in the build version XML |
226+
| CSM004 | FileVersion property not provided AND FileVersionMajor property not found to create it from |
227+
| CSM005 | FileVersion property not provided AND FileVersionMinor property not found to create it from |
228+
| CSM006 | FileVersion property not provided AND FileVersionBuild property not found to create it from |
229+
| CSM007 | FileVersion property not provided AND FileVersionRevision property not found to create it from |
230+
| CSM100 | BuildMajor value must be in range [0-99999] |
231+
| CSM101 | BuildMinor value must be in range [0-49999] |
232+
| CSM102 | BuildPatch value must be in range [0-9999] |
233+
| CSM103 | PreRelease Name is unknown |
234+
| CSM104 | PreReleaseNumber value must be in range [0-99] |
235+
| CSM105 | If CiBuildIndex is set then CiBuildName must also be set; If CiBuildIndex is NOT set then CiBuildName must not be set. |
236+
| CSM106 | CiBuildIndex does not match syntax defined by CSemVer |
237+
| CSM107 | CiBuildName does not match syntax defined by CSemVer |
238+
| CSM200 | BuildVersionXml is required and must not be all whitespace |
239+
| CSM201 | Specified BuildVersionXml does not exist `$(BuildVersionXml)`|
240+
| CSM202 | [Warning] Unexpected attribute on BuildVersionData Element |

src/Ubiquity.NET.Versioning.Build.Tasks/CreateVersionInfo.cs

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public override bool Execute( )
7575

7676
if(!ValidateInput())
7777
{
78-
Log.LogError("Input validation failed");
7978
return false;
8079
}
8180

@@ -196,19 +195,19 @@ private bool ValidateInput( )
196195
bool hasInputError = false;
197196
if(BuildMajor < 0 || BuildMajor > 99999)
198197
{
199-
Log.LogError( "BuildMajor value must be in range [0-99999]" );
198+
LogError("CSM100", "BuildMajor value must be in range [0-99999]" );
200199
hasInputError = true;
201200
}
202201

203202
if(BuildMinor < 0 || BuildMinor > 49999)
204203
{
205-
Log.LogError( "BuildMinor value must be in range [0-49999]" );
204+
LogError("CSM101", "BuildMinor value must be in range [0-49999]" );
206205
hasInputError = true;
207206
}
208207

209208
if(BuildPatch < 0 || BuildPatch > 9999)
210209
{
211-
Log.LogError( "BuildPatch value must be in range [0-99999]" );
210+
LogError("CSM102", "BuildPatch value must be in range [0-9999]" );
212211
hasInputError = true;
213212
}
214213

@@ -218,59 +217,53 @@ private bool ValidateInput( )
218217
{
219218
if(!PreReleaseShortNames.Contains( PreReleaseName, StringComparer.InvariantCultureIgnoreCase ))
220219
{
221-
Log.LogError( "PreRelease Name is unknown" );
220+
LogError("CSM103", "PreRelease Name is unknown" );
222221
hasInputError = true;
223222
}
224223
}
225224
}
226225

227226
if(PreReleaseNumber < 0 || PreReleaseNumber > 99)
228227
{
229-
Log.LogError( "PreReleaseNumber value must be in range [0-99]" );
228+
LogError("CSM104", "PreReleaseNumber value must be in range [0-99]" );
230229
hasInputError = true;
231230
}
232231

233232
if(PreReleaseFix < 0 || PreReleaseFix > 99)
234233
{
235-
Log.LogError( "PreReleaseFix value must be in range [0-99]" );
234+
LogError("CSM104", "PreReleaseFix value must be in range [0-99]" );
236235
hasInputError = true;
237236
}
238237

239238
if(string.IsNullOrWhiteSpace( CiBuildIndex ) != string.IsNullOrWhiteSpace( CiBuildName ))
240239
{
241-
Log.LogError( "If CiBuildIndex is set then CiBuildName must also be set; If CiBuildIndex is NOT set then CiBuildName must not be set." );
240+
LogError("CSM105", "If CiBuildIndex is set then CiBuildName must also be set; If CiBuildIndex is NOT set then CiBuildName must not be set." );
242241
hasInputError = true;
243242
}
244243

245244
if(CiBuildIndex != null && !CiBuildIdRegEx.IsMatch( CiBuildIndex ))
246245
{
247-
Log.LogError( "CiBuildIndex does not match syntax defined by CSemVer" );
246+
LogError("CSM106", "CiBuildIndex does not match syntax defined by CSemVer" );
248247
hasInputError = true;
249248
}
250249

251250
if(CiBuildName != null && !CiBuildIdRegEx.IsMatch( CiBuildName ))
252251
{
253-
Log.LogError( "CiBuildName does not match syntax defined by CSemVer" );
254-
hasInputError = true;
255-
}
256-
257-
if(!string.IsNullOrEmpty( BuildMeta ) && BuildMeta!.Length > 20)
258-
{
259-
Log.LogError( "Build metadata, if provided, must not exceed 20 characters" );
252+
LogError("CSM107", "CiBuildName does not match syntax defined by CSemVer" );
260253
hasInputError = true;
261254
}
262255

263256
return !hasInputError;
264257
}
265258

266-
//private void LogError(
267-
// string code,
268-
// /*[StringSyntax(StringSyntaxAttribute.CompositeFormat)]*/ string message,
269-
// params object[] messageArgs
270-
// )
271-
//{
272-
// Log.LogError("Task", code, null, null, 0, 0, 0, 0, message, messageArgs);
273-
//}
259+
private void LogError(
260+
string code,
261+
/*[StringSyntax(StringSyntaxAttribute.CompositeFormat)]*/ string message,
262+
params object[] messageArgs
263+
)
264+
{
265+
Log.LogError($"{nameof(CreateVersionInfo)} Task", code, null, null, 0, 0, 0, 0, message, messageArgs);
266+
}
274267

275268
private static int ComputePreReleaseIndex( string preRelName )
276269
{

src/Ubiquity.NET.Versioning.Build.Tasks/ParseBuildVersionXml.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ public override bool Execute( )
4242
try
4343
{
4444
Log.LogMessage(MessageImportance.Low, $"+{nameof(ParseBuildVersionXml)} Task");
45+
if (string.IsNullOrWhiteSpace(BuildVersionXml))
46+
{
47+
LogError("CSM200", "BuildVersionXml is required and must not be all whitespace");
48+
return false;
49+
}
50+
51+
if (!File.Exists(BuildVersionXml))
52+
{
53+
LogError("CSM201", $"Specified BuildVersionXml does not exist '{BuildVersionXml}'");
54+
return false;
55+
}
4556

4657
using var stream = File.OpenText( BuildVersionXml );
4758
var xdoc = System.Xml.Linq.XDocument.Load( stream, System.Xml.Linq.LoadOptions.None );
@@ -82,7 +93,7 @@ public override bool Execute( )
8293
break;
8394

8495
default:
85-
Log.LogWarning( "Unexpected attribute {0}", attrib.Name.LocalName );
96+
LogWarning( "CSM202", "Unexpected attribute {0}", attrib.Name.LocalName );
8697
break;
8798
}
8899
}
@@ -110,5 +121,23 @@ public override bool Execute( )
110121
return false;
111122
}
112123
}
124+
125+
private void LogError(
126+
string code,
127+
/*[StringSyntax(StringSyntaxAttribute.CompositeFormat)]*/ string message,
128+
params object[] messageArgs
129+
)
130+
{
131+
Log.LogError($"{nameof(ParseBuildVersionXml)} Task", code, null, null, 0, 0, 0, 0, message, messageArgs);
132+
}
133+
134+
private void LogWarning(
135+
string code,
136+
/*[StringSyntax(StringSyntaxAttribute.CompositeFormat)]*/ string message,
137+
params object[] messageArgs
138+
)
139+
{
140+
Log.LogWarning($"{nameof(ParseBuildVersionXml)} Task", code, null, null, 0, 0, 0, 0, message, messageArgs);
141+
}
113142
}
114143
}

0 commit comments

Comments
 (0)