using System;
namespace ComputeSharp.Exceptions;
///
/// A custom type that indicates when a shader compilation with the DXC compiler has failed.
///
public sealed class DxcCompilationException : Exception
{
///
/// Creates a new instance.
///
/// The error message produced by the DXC compiler.
internal DxcCompilationException(string error)
: base(GetExceptionMessage(error))
{
}
///
/// Gets a formatted exception message for a given compilation error.
///
/// The input compilatin error message from the DXC compiler.
/// A formatted error message for a new instance.
private static string GetExceptionMessage(string error)
{
#if NET6_0_OR_GREATER
ReadOnlySpan message = error.AsSpan().Trim();
#else
string message = error.Trim();
#endif
return
$"""The DXC compiler encountered one or more errors while trying to compile the shader: "{message}". """ +
$"""Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp. """ +
$"""If you're sure that your C# shader code is valid, please open an issue an include a working repro and this error message.""";
}
}