posthog icon indicating copy to clipboard operation
posthog copied to clipboard

HogQL: More helpful error messages

Open timgl opened this issue 1 year ago • 2 comments

Is your feature request related to a problem?

These messages are helpful image

This message is not image

Describe the solution you'd like

Return more helpful error messages. I know there are some security concerns here, but perhaps we can limit it to certain types of error codes or even have the HogQL parses realise these types of errors? I assume this might be part of the type system? @Gilbert09

Describe alternatives you've considered

Additional context

Thank you for your feature request – we love each and every one!

timgl avatar Feb 09 '24 21:02 timgl

More context: We should add user_safe=True to all errors that are safe to show: https://github.com/PostHog/posthog/blob/cdeb283151af43dced5f7e32ffd31c3967b6e231/posthog/errors.py#L342

We took the safe/cautious approach by default to avoid accidentally leaking anything...

mariusandra avatar Feb 12 '24 09:02 mariusandra

I think this is now fixed by @mariusandra here: https://github.com/PostHog/posthog/pull/20292

Gilbert09 avatar Feb 14 '24 09:02 Gilbert09

@Gilbert09 I'm still getting this occasionally, where it looks like there are no results but there's actually an error

select sum(JSONExtractInt(line, 'quantity')) as invoiced_usage, customer_id
, mrr
-- max(tupleElement(period_start, 1)),
-- max(tupleElement(period_end, 1))

from (
select arrayJoin(JSONExtractArrayRaw(JSONExtractString(data, 'lines'), 'data')) as line, customer_id, JSONExtractInt(mrr_per_product, 'session_replay') as mrr, period_start, period_end


from invoice_with_annual
        where JSONExtractInt(mrr_per_product, 'session_replay') > 0
        and toStartOfMonth(tupleElement(period_end, 1)) = toStartOfMonth(now() - toIntervalMonth(1))
        and JSONExtractString(line, 'price', 'nickname') LIKE '%session_replay%'
)
group by customer_id
image

timgl avatar Feb 20 '24 14:02 timgl

Another issue. Note the group by 1, which isn't allowed and causes an exception in Clickhouse, but doesn't return the error in the API at all.

select sum(JSONExtractInt(line, 'quantity')) as invoiced_usage, customer_id
, mrr
-- max(tupleElement(period_start, 1)),
-- max(tupleElement(period_end, 1))

from (
select arrayJoin(JSONExtractArrayRaw(JSONExtractString(data, 'lines'), 'data')) as line, customer_id, JSONExtractInt(mrr_per_product, 'session_replay') as mrr, period_start, period_end


from invoice_with_annual
        where JSONExtractInt(mrr_per_product, 'session_replay') > 0
        and toStartOfMonth(tupleElement(period_end, 1)) = toStartOfMonth(now() - toIntervalMonth(1))
        and JSONExtractString(line, 'price', 'nickname') LIKE '%session_replay%'
)
group by 1, customer_id

timgl avatar Feb 28 '24 10:02 timgl

This simpler query gives me the same non-error locally:

select toDate(timestamp) as timestamp, count(), event
from events
where {filters} and timestamp <= now()
group by 1, timestamp
order by timestamp asc
limit 100 

A fix is here: https://github.com/PostHog/posthog/pull/20611

mariusandra avatar Feb 28 '24 15:02 mariusandra

I think we have this handled for a lot of cases

Twixes avatar Apr 29 '24 15:04 Twixes