Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for runtime warnings #750

Merged
merged 2 commits into from Oct 25, 2019
Merged

API for runtime warnings #750

merged 2 commits into from Oct 25, 2019

Conversation

exyi
Copy link
Member

@exyi exyi commented Sep 1, 2019

RuntimeWarningCollector is a service, where a new warning will can be
added using the Warn method. Warning is an instance of
DotvvmRuntimeWarning, contains a message and may contain a reference to
an exception and a bindable object.

By default, warnings are collected in Debug mode. They are displayed in
browser JS console and forwarded to Asp.Net Core logging.

IDotvvmWarningSink is extensibility point for people that want to
collect these warnings on their own.

As a demo, HtmlWriter reports warnings when elements that should be
always self-closing contain some content, as the browser will interpret
the content as sibling.

related to #745, but does not close it since this PR introduces only the infrastructure.

Also note that I had to move rendering of resources in postback after rendering of PostBack.Update controls. Since we support resource registration in the Render phase, this would need to be done anyway. I have altered IHtmlWriter and IViewModelSerializer, but these interfaces are so bound to the implementations in framework, that I don't believe somebody has implemented them...

The public API looks like this:

namespace DotVVM.Framework.Runtime
{
    public interface IDotvvmWarningSink
    {
        void RuntimeWarning(DotvvmRuntimeWarning warning);
    }
    public class DotvvmRuntimeWarning
    {
        public DotvvmRuntimeWarning(string message, Exception relatedException = null, DotvvmBindableObject relatedControl = null);

        public string Message { get; }
        public Exception RelatedException { get; }
        public DotvvmBindableObject RelatedControl { get; }

        public override string ToString();
    }

    public class RuntimeWarningCollector
    {
        public bool Enabled { get; }

        public RuntimeWarningCollector(IEnumerable<IDotvvmWarningSink> sinks, DotvvmConfiguration config);

        public void Warn(DotvvmRuntimeWarning warning);


        public List<DotvvmRuntimeWarning> GetWarnings() => warnings.ToList();
    }
}

RuntimeWarningCollector is a service, where a new warning will can be
added using the `Warn` method. Warning is an instance of
DotvvmRuntimeWarning, contains a message and may contain a reference to
an exception and a bindable object.

By default, warnings are collected in Debug mode. They are displayed in
browser JS console and forwarded to Asp.Net Core logging.

IDotvvmWarningSink is extensibility point for people that want to
collect these warnings on their own.

As a demo, HtmlWriter reports warnings when elements that should be
always self-closing contain some content, as the browser will interpret
the content as sibling
src/DotVVM.Framework/Controls/HtmlWriter.cs Outdated Show resolved Hide resolved
src/DotVVM.Framework/Controls/HtmlWriter.cs Outdated Show resolved Hide resolved
@quigamdev quigamdev merged commit 27c579b into master Oct 25, 2019
@exyi exyi deleted the runtime-warnings branch October 25, 2019 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants